home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / man / cat.1 / perlfunc.1 < prev    next >
Text File  |  1995-07-25  |  173KB  |  4,027 lines

  1.  
  2.  
  3.  
  4.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.           perlfunc - Perl builtin functions
  10.  
  11.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  12.           The functions in this section can serve as terms in an
  13.           expression.  They fall into two major categories: list
  14.           operators and named unary operators.  These differ in their
  15.           precedence relationship with a following comma.  (See the
  16.           precedence table in the _p_e_r_l_o_p manpage.)  List operators
  17.           take more than one argument, while unary operators can never
  18.           take more than one argument.  Thus, a comma terminates the
  19.           argument of a unary operator, but merely separates the
  20.           arguments of a list operator.  A unary operator generally
  21.           provides a scalar context to its argument, while a list
  22.           operator may provide either scalar and list contexts for its
  23.           arguments.  If it does both, the scalar arguments will be
  24.           first, and the list argument will follow.  (Note that there
  25.           can only ever be one list argument.)  For instance, _s_p_l_i_c_e()
  26.           has three scalar arguments followed by a list.
  27.  
  28.           In the syntax descriptions that follow, list operators that
  29.           expect a list (and provide list context for the elements of
  30.           the list) are shown with LIST as an argument.  Such a list
  31.           may consist of any combination of scalar arguments or list
  32.           values; the list values will be included in the list as if
  33.           each individual element were interpolated at that point in
  34.           the list, forming a longer single-dimensional list value.
  35.           Elements of the LIST should be separated by commas.
  36.  
  37.           Any function in the list below may be used either with or
  38.           without parentheses around its arguments.  (The syntax
  39.           descriptions omit the parens.)  If you use the parens, the
  40.           simple (but occasionally surprising) rule is this: It _L_O_O_K_S
  41.           like a function, therefore it _I_S a function, and precedence
  42.           doesn't matter.  Otherwise it's a list operator or unary
  43.           operator, and precedence does matter.  And whitespace
  44.           between the function and left parenthesis doesn't count--so
  45.           you need to be careful sometimes:
  46.  
  47.               print 1+2+3;        # Prints 6.
  48.               print(1+2) + 3;     # Prints 3.
  49.               print (1+2)+3;      # Also prints 3!
  50.               print +(1+2)+3;     # Prints 6.
  51.               print ((1+2)+3);    # Prints 6.
  52.  
  53.           If you run Perl with the ----wwww switch it can warn you about
  54.           this.  For example, the third line above produces:
  55.  
  56.               print (...) interpreted as function at - line 1.
  57.               Useless use of integer addition in void context at - line 1.
  58.  
  59.           For functions that can be used in either a scalar or list
  60.  
  61.  
  62.  
  63.      Page 1                                          (printed 6/30/95)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  71.  
  72.  
  73.  
  74.           context, non-abortive failure is generally indicated in a
  75.           scalar context by returning the undefined value, and in a
  76.           list context by returning the null list.
  77.  
  78.           Remember the following rule:
  79.  
  80.           o+    _T_H_E_R_E _I_S _N_O _G_E_N_E_R_A_L _R_U_L_E _F_O_R _C_O_N_V_E_R_T_I_N_G _A _L_I_S_T _I_N_T_O _A
  81.                _S_C_A_L_A_R!
  82.  
  83.           Each operator and function decides which sort of value it
  84.           would be most appropriate to return in a scalar context.
  85.           Some operators return the length of the list that would have
  86.           been returned in a list context.  Some operators return the
  87.           first value in the list.  Some operators return the last
  88.           value in the list.  Some operators return a count of
  89.           successful operations.  In general, they do what you want,
  90.           unless you want consistency.
  91.  
  92.           -X FILEHANDLE
  93.  
  94.           -X EXPR
  95.  
  96.           -X      A file test, where X is one of the letters listed
  97.                   below.  This unary operator takes one argument,
  98.                   either a filename or a filehandle, and tests the
  99.                   associated file to see if something is true about
  100.                   it.  If the argument is omitted, tests $_, except
  101.                   for -t, which tests STDIN.  Unless otherwise
  102.                   documented, it returns 1 for TRUE and '' for FALSE,
  103.                   or the undefined value if the file doesn't exist.
  104.                   Despite the funny names, precedence is the same as
  105.                   any other named unary operator, and the argument may
  106.                   be parenthesized like any other unary operator.  The
  107.                   operator may be any of:
  108.  
  109.                       -r  File is readable by effective uid/gid.
  110.                       -w  File is writable by effective uid/gid.
  111.                       -x  File is executable by effective uid/gid.
  112.                       -o  File is owned by effective uid.
  113.  
  114.                       -R  File is readable by real uid/gid.
  115.                       -W  File is writable by real uid/gid.
  116.                       -X  File is executable by real uid/gid.
  117.                       -O  File is owned by real uid.
  118.  
  119.                       -e  File exists.
  120.                       -z  File has zero size.
  121.                       -s  File has non-zero size (returns size).
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.      Page 2                                          (printed 6/30/95)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  137.  
  138.  
  139.  
  140.                       -f  File is a plain file.
  141.                       -d  File is a directory.
  142.                       -l  File is a symbolic link.
  143.                       -p  File is a named pipe (FIFO).
  144.                       -S  File is a socket.
  145.                       -b  File is a block special file.
  146.                       -c  File is a character special file.
  147.                       -t  Filehandle is opened to a tty.
  148.  
  149.                       -u  File has setuid bit set.
  150.                       -g  File has setgid bit set.
  151.                       -k  File has sticky bit set.
  152.  
  153.                       -T  File is a text file.
  154.                       -B  File is a binary file (opposite of -T).
  155.  
  156.                       -M  Age of file in days when script started.
  157.                       -A  Same for access time.
  158.                       -C  Same for inode change time.
  159.  
  160.                   The interpretation of the file permission operators
  161.                   -r, -R, -w, -W, -x and -X is based solely on the
  162.                   mode of the file and the uids and gids of the user.
  163.                   There may be other reasons you can't actually read,
  164.                   write or execute the file.  Also note that, for the
  165.                   superuser, -r, -R, -w and -W always return 1, and -x
  166.                   and -X return 1 if any execute bit is set in the
  167.                   mode.  Scripts run by the superuser may thus need to
  168.                   do a _s_t_a_t() in order to determine the actual mode of
  169.                   the file, or temporarily set the uid to something
  170.                   else.
  171.  
  172.                   Example:
  173.  
  174.                       while (<>) {
  175.                           chop;
  176.                           next unless -f $_;      # ignore specials
  177.                           ...
  178.                       }
  179.  
  180.                   Note that -s/a/b/ does not do a negated
  181.                   substitution.  Saying -exp($foo) still works as
  182.                   expected, however--only single letters following a
  183.                   minus are interpreted as file tests.
  184.  
  185.                   The -T and -B switches work as follows.  The first
  186.                   block or so of the file is examined for odd
  187.                   characters such as strange control codes or
  188.                   characters with the high bit set.  If too many odd
  189.                   characters (>30%) are found, it's a -B file,
  190.                   otherwise it's a -T file.  Also, any file containing
  191.                   null in the first block is considered a binary file.
  192.  
  193.  
  194.  
  195.      Page 3                                          (printed 6/30/95)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  203.  
  204.  
  205.  
  206.                   If -T or -B is used on a filehandle, the current
  207.                   stdio buffer is examined rather than the first
  208.                   block.  Both -T and -B return TRUE on a null file,
  209.                   or a file at EOF when testing a filehandle.
  210.  
  211.                   If any of the file tests (or either the _s_t_a_t() or
  212.                   _l_s_t_a_t() operators) are given the special filehandle
  213.                   consisting of a solitary underline, then the stat
  214.                   structure of the previous file test (or stat
  215.                   operator) is used, saving a system call.  (This
  216.                   doesn't work with -t, and you need to remember that
  217.                   _l_s_t_a_t() and -l will leave values in the stat
  218.                   structure for the symbolic link, not the real file.)
  219.                   Example:
  220.  
  221.                       print "Can do.\n" if -r $a || -w _ || -x _;
  222.  
  223.                       stat($filename);
  224.                       print "Readable\n" if -r _;
  225.                       print "Writable\n" if -w _;
  226.                       print "Executable\n" if -x _;
  227.                       print "Setuid\n" if -u _;
  228.                       print "Setgid\n" if -g _;
  229.                       print "Sticky\n" if -k _;
  230.                       print "Text\n" if -T _;
  231.                       print "Binary\n" if -B _;
  232.  
  233.  
  234.           abs VALUE
  235.                   Returns the absolute value of its argument.
  236.  
  237.           accept NEWSOCKET,GENERICSOCKET
  238.                   Accepts an incoming socket connect, just as the
  239.                   _a_c_c_e_p_t(2) system call does.  Returns the packed
  240.                   address if it succeeded, FALSE otherwise.  See
  241.                   example in the _p_e_r_l_i_p_c manpage.
  242.  
  243.           alarm SECONDS
  244.                   Arranges to have a SIGALRM delivered to this process
  245.                   after the specified number of seconds have elapsed.
  246.                   (On some machines, unfortunately, the elapsed time
  247.                   may be up to one second less than you specified
  248.                   because of how seconds are counted.)  Only one timer
  249.                   may be counting at once.  Each call disables the
  250.                   previous timer, and an argument of 0 may be supplied
  251.                   to cancel the previous timer without starting a new
  252.                   one.  The returned value is the amount of time
  253.                   remaining on the previous timer.
  254.  
  255.                   For sleeps of finer granularity than one second, you
  256.                   may use Perl's _s_y_s_c_a_l_l() interface to access
  257.                   _s_e_t_i_t_i_m_e_r(2) if your system supports it, or else see
  258.  
  259.  
  260.  
  261.      Page 4                                          (printed 6/30/95)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  269.  
  270.  
  271.  
  272.                   the select() entry elsewhere in this documentbelow.
  273.  
  274.           atan2 Y,X
  275.                   Returns the arctangent of Y/X in the range - to .
  276.  
  277.           bind SOCKET,NAME
  278.                   Binds a network address to a socket, just as the
  279.                   bind system call does.  Returns TRUE if it
  280.                   succeeded, FALSE otherwise.  NAME should be a packed
  281.                   address of the appropriate type for the socket.  See
  282.                   example in the _p_e_r_l_i_p_c manpage.
  283.  
  284.           binmode FILEHANDLE
  285.                   Arranges for the file to be read or written in
  286.                   "binary" mode in operating systems that distinguish
  287.                   between binary and text files.  Files that are not
  288.                   in binary mode have CR LF sequences translated to LF
  289.                   on input and LF translated to CR LF on output.
  290.                   Binmode has no effect under Unix; in DOS, it may be
  291.                   imperative.  If FILEHANDLE is an expression, the
  292.                   value is taken as the name of the filehandle.
  293.  
  294.           bless REF,PACKAGE
  295.  
  296.           bless REF
  297.                   This function tells the referenced object (passed as
  298.                   REF) that it is now an object in PACKAGE--or the
  299.                   current package if no PACKAGE is specified, which is
  300.                   the usual case.  It returns the reference for
  301.                   convenience, since a _b_l_e_s_s() is often the last thing
  302.                   in a constructor.  See the _p_e_r_l_o_b_j manpage for more
  303.                   about the blessing (and blessings) of objects.
  304.  
  305.           caller EXPR
  306.  
  307.           caller  Returns the context of the current subroutine call.
  308.                   In a scalar context, returns TRUE if there is a
  309.                   caller, that is, if we're in a subroutine or _e_v_a_l()
  310.                   or _r_e_q_u_i_r_e(), and FALSE otherwise.  In a list
  311.                   context, returns
  312.  
  313.                       ($package,$filename,$line) = caller;
  314.  
  315.                   With EXPR, it returns some extra information that
  316.                   the debugger uses to print a stack trace.  The value
  317.                   of EXPR indicates how many call frames to go back
  318.                   before the current one.
  319.  
  320.           chdir EXPR
  321.                   Changes the working directory to EXPR, if possible.
  322.                   If EXPR is omitted, changes to home directory.
  323.                   Returns TRUE upon success, FALSE otherwise.  See
  324.  
  325.  
  326.  
  327.      Page 5                                          (printed 6/30/95)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  335.  
  336.  
  337.  
  338.                   example under _d_i_e().
  339.  
  340.           chmod LIST
  341.                   Changes the permissions of a list of files.  The
  342.                   first element of the list must be the numerical
  343.                   mode.  Returns the number of files successfully
  344.                   changed.
  345.  
  346.                       $cnt = chmod 0755, 'foo', 'bar';
  347.                       chmod 0755, @executables;
  348.  
  349.  
  350.           chomp VARIABLE
  351.  
  352.           chomp LIST
  353.  
  354.           chomp   This is a slightly safer version of chop (see
  355.                   below).  It removes any line ending that corresponds
  356.                   to the current value of $/ (also known as
  357.                   $INPUT_RECORD_SEPARATOR in the English module).  It
  358.                   returns the number of characters removed.  It's
  359.                   often used to remove the newline from the end of an
  360.                   input record when you're worried that the final
  361.                   record may be missing its newline.  When in
  362.                   paragraph mode ($/ = ""), it removes all trailing
  363.                   newlines from the string.  If VARIABLE is omitted,
  364.                   it chomps $_.  Example:
  365.  
  366.                       while (<>) {
  367.                           chomp;  # avoid \n on last field
  368.                           @array = split(/:/);
  369.                           ...
  370.                       }
  371.  
  372.                   You can actually chomp anything that's an lvalue,
  373.                   including an assignment:
  374.  
  375.                       chomp($cwd = `pwd`);
  376.                       chomp($answer = <STDIN>);
  377.  
  378.                   If you chomp a list, each element is chomped, and
  379.                   the total number of characters removed is returned.
  380.  
  381.           chop VARIABLE
  382.  
  383.           chop LIST
  384.  
  385.           chop    Chops off the last character of a string and returns
  386.                   the character chopped.  It's used primarily to
  387.                   remove the newline from the end of an input record,
  388.                   but is much more efficient than s/\n// because it
  389.                   neither scans nor copies the string.  If VARIABLE is
  390.  
  391.  
  392.  
  393.      Page 6                                          (printed 6/30/95)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  401.  
  402.  
  403.  
  404.                   omitted, chops $_.  Example:
  405.  
  406.                       while (<>) {
  407.                           chop;   # avoid \n on last field
  408.                           @array = split(/:/);
  409.                           ...
  410.                       }
  411.  
  412.                   You can actually chop anything that's an lvalue,
  413.                   including an assignment:
  414.  
  415.                       chop($cwd = `pwd`);
  416.                       chop($answer = <STDIN>);
  417.  
  418.                   If you chop a list, each element is chopped.  Only
  419.                   the value of the last chop is returned.
  420.  
  421.           chown LIST
  422.                   Changes the owner (and group) of a list of files.
  423.                   The first two elements of the list must be the
  424.                   _N_U_M_E_R_I_C_A_L uid and gid, in that order.  Returns the
  425.                   number of files successfully changed.
  426.  
  427.                       $cnt = chown $uid, $gid, 'foo', 'bar';
  428.                       chown $uid, $gid, @filenames;
  429.  
  430.                   Here's an example that looks up non-numeric uids in
  431.                   the passwd file:
  432.  
  433.                       print "User: ";
  434.                       chop($user = <STDIN>);
  435.                       print "Files: "
  436.                       chop($pattern = <STDIN>);
  437.  
  438.                       ($login,$pass,$uid,$gid) = getpwnam($user)
  439.                           or die "$user not in passwd file";
  440.  
  441.                       @ary = <${pattern}>;        # expand filenames
  442.                       chown $uid, $gid, @ary;
  443.  
  444.  
  445.           chr NUMBER
  446.                   Returns the character represented by that NUMBER in
  447.                   the character set.  For example, chr(65) is "A" in
  448.                   ASCII.
  449.  
  450.           chroot FILENAME
  451.                   Does the same as the system call of that name.  If
  452.                   you don't know what it does, don't worry about it.
  453.                   If FILENAME is omitted, does chroot to $_.
  454.  
  455.  
  456.  
  457.  
  458.  
  459.      Page 7                                          (printed 6/30/95)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  467.  
  468.  
  469.  
  470.           close FILEHANDLE
  471.                   Closes the file or pipe associated with the file
  472.                   handle, returning TRUE only if stdio successfully
  473.                   flushes buffers and closes the system file
  474.                   descriptor.  You don't have to close FILEHANDLE if
  475.                   you are immediately going to do another open on it,
  476.                   since open will close it for you.  (See _o_p_e_n().)
  477.                   However, an explicit close on an input file resets
  478.                   the line counter ($.), while the implicit close done
  479.                   by _o_p_e_n() does not.  Also, closing a pipe will wait
  480.                   for the process executing on the pipe to complete,
  481.                   in case you want to look at the output of the pipe
  482.                   afterwards.  Closing a pipe explicitly also puts the
  483.                   status value of the command into $?.  Example:
  484.  
  485.                       open(OUTPUT, '|sort >foo'); # pipe to sort
  486.                       ...                         # print stuff to output
  487.                       close OUTPUT;               # wait for sort to finish
  488.                       open(INPUT, 'foo');         # get sort's results
  489.  
  490.                   FILEHANDLE may be an expression whose value gives
  491.                   the real filehandle name.
  492.  
  493.           closedir DIRHANDLE
  494.                   Closes a directory opened by _o_p_e_n_d_i_r().
  495.  
  496.           connect SOCKET,NAME
  497.                   Attempts to connect to a remote socket, just as the
  498.                   connect system call does.  Returns TRUE if it
  499.                   succeeded, FALSE otherwise.  NAME should be a
  500.                   package address of the appropriate type for the
  501.                   socket.  See example in the _p_e_r_l_i_p_c manpage.
  502.  
  503.           cos EXPR
  504.                   Returns the cosine of EXPR (expressed in radians).
  505.                   If EXPR is omitted takes cosine of $_.
  506.  
  507.           crypt PLAINTEXT,SALT
  508.                   Encrypts a string exactly like the _c_r_y_p_t(3) function
  509.                   in the C library.  Useful for checking the password
  510.                   file for lousy passwords, amongst other things.
  511.                   Only the guys wearing white hats should do this.
  512.  
  513.                   Here's an example that makes sure that whoever runs
  514.                   this program knows their own password:
  515.  
  516.                       $pwd = (getpwuid($<))[1];
  517.                       $salt = substr($pwd, 0, 2);
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.      Page 8                                          (printed 6/30/95)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  533.  
  534.  
  535.  
  536.                       system "stty -echo";
  537.                       print "Password: ";
  538.                       chop($word = <STDIN>);
  539.                       print "\n";
  540.                       system "stty echo";
  541.  
  542.                       if (crypt($word, $salt) ne $pwd) {
  543.                           die "Sorry...\n";
  544.                       } else {
  545.                           print "ok\n";
  546.                       }
  547.  
  548.                   Of course, typing in your own password to whoever
  549.                   asks you for it is unwise at best.
  550.  
  551.           dbmclose ASSOC_ARRAY
  552.                   [This function has been superseded by the _u_n_t_i_e()
  553.                   function.]
  554.  
  555.                   Breaks the binding between a DBM file and an
  556.                   associative array.
  557.  
  558.           dbmopen ASSOC,DBNAME,MODE
  559.                   [This function has been superseded by the _t_i_e()
  560.                   function.]
  561.  
  562.                   This binds a _d_b_m(3) or _n_d_b_m(3) file to an
  563.                   associative array.  ASSOC is the name of the
  564.                   associative array.  (Unlike normal open, the first
  565.                   argument is _N_O_T a filehandle, even though it looks
  566.                   like one).  DBNAME is the name of the database
  567.                   (without the ._d_i_r or ._p_a_g extension).  If the
  568.                   database does not exist, it is created with
  569.                   protection specified by MODE (as modified by the
  570.                   _u_m_a_s_k()).  If your system only supports the older
  571.                   DBM functions, you may perform only one _d_b_m_o_p_e_n() in
  572.                   your program.  If your system has neither DBM nor
  573.                   ndbm, calling _d_b_m_o_p_e_n() produces a fatal error.
  574.  
  575.                   If you don't have write access to the DBM file, you
  576.                   can only read associative array variables, not set
  577.                   them.  If you want to test whether you can write,
  578.                   either use file tests or try setting a dummy array
  579.                   entry inside an _e_v_a_l(), which will trap the error.
  580.  
  581.                   Note that functions such as _k_e_y_s() and _v_a_l_u_e_s() may
  582.                   return huge array values when used on large DBM
  583.                   files.  You may prefer to use the _e_a_c_h() function to
  584.                   iterate over large DBM files.  Example:
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.      Page 9                                          (printed 6/30/95)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  599.  
  600.  
  601.  
  602.                       # print out history file offsets
  603.                       dbmopen(%HIST,'/usr/lib/news/history',0666);
  604.                       while (($key,$val) = each %HIST) {
  605.                           print $key, ' = ', unpack('L',$val), "\n";
  606.                       }
  607.                       dbmclose(%HIST);
  608.  
  609.  
  610.           defined EXPR
  611.                   Returns a boolean value saying whether the lvalue
  612.                   EXPR has a real value or not.  Many operations
  613.                   return the undefined value under exceptional
  614.                   conditions, such as end of file, uninitialized
  615.                   variable, system error and such.  This function
  616.                   allows you to distinguish between an undefined null
  617.                   scalar and a defined null scalar with operations
  618.                   that might return a real null string, such as
  619.                   referencing elements of an array.  You may also
  620.                   check to see if arrays or subroutines exist.  Use of
  621.                   defined on predefined variables is not guaranteed to
  622.                   produce intuitive results.
  623.  
  624.                   When used on a hash array element, it tells you
  625.                   whether the value is defined, not whether the key
  626.                   exists in the hash.  Use _e_x_i_s_t_s() for that.
  627.  
  628.                   Examples:
  629.  
  630.                       print if defined $switch{'D'};
  631.                       print "$val\n" while defined($val = pop(@ary));
  632.                       die "Can't readlink $sym: $!"
  633.                           unless defined($value = readlink $sym);
  634.                       eval '@foo = ()' if defined(@foo);
  635.                       die "No XYZ package defined" unless defined %_XYZ;
  636.                       sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
  637.  
  638.                   See also _u_n_d_e_f().
  639.  
  640.           delete EXPR
  641.                   Deletes the specified value from its hash array.
  642.                   Returns the deleted value, or the undefined value if
  643.                   nothing was deleted.  Deleting from $ENV{} modifies
  644.                   the environment.  Deleting from an array tied to a
  645.                   DBM file deletes the entry from the DBM file.  (But
  646.                   deleting from a _t_i_e()d hash doesn't necessarily
  647.                   return anything.)
  648.  
  649.                   The following deletes all the values of an
  650.                   associative array:
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.      Page 10                                         (printed 6/30/95)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  665.  
  666.  
  667.  
  668.                       foreach $key (keys %ARRAY) {
  669.                           delete $ARRAY{$key};
  670.                       }
  671.  
  672.                   (But it would be faster to use the _u_n_d_e_f() command.)
  673.                   Note that the EXPR can be arbitrarily complicated as
  674.                   long as the final operation is a hash key lookup:
  675.  
  676.                       delete $ref->[$x][$y]{$key};
  677.  
  678.  
  679.           die LIST
  680.                   Outside of an _e_v_a_l(), prints the value of LIST to
  681.                   STDERR and exits with the current value of $!
  682.                   (errno).  If $! is 0, exits with the value of ($? >>
  683.                   8) (`command` status).  If ($? >> 8) is 0, exits
  684.                   with 255.  Inside an _e_v_a_l(), the error message is
  685.                   stuffed into $@.  and the _e_v_a_l() is terminated with
  686.                   the undefined value.
  687.  
  688.                   Equivalent examples:
  689.  
  690.                       die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
  691.                       chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
  692.  
  693.                   If the value of EXPR does not end in a newline, the
  694.                   current script line number and input line number (if
  695.                   any) are also printed, and a newline is supplied.
  696.                   Hint: sometimes appending ", stopped" to your
  697.                   message will cause it to make better sense when the
  698.                   string "at foo line 123" is appended.  Suppose you
  699.                   are running script "canasta".
  700.  
  701.                       die "/etc/games is no good";
  702.                       die "/etc/games is no good, stopped";
  703.  
  704.                   produce, respectively
  705.  
  706.                       /etc/games is no good at canasta line 123.
  707.                       /etc/games is no good, stopped at canasta line 123.
  708.  
  709.                   See also _e_x_i_t() and _w_a_r_n().
  710.  
  711.           do BLOCK
  712.                   Not really a function.  Returns the value of the
  713.                   last command in the sequence of commands indicated
  714.                   by BLOCK.  When modified by a loop modifier,
  715.                   executes the BLOCK once before testing the loop
  716.                   condition.  (On other statements the loop modifiers
  717.                   test the conditional first.)
  718.  
  719.  
  720.  
  721.  
  722.  
  723.      Page 11                                         (printed 6/30/95)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  731.  
  732.  
  733.  
  734.           do SUBROUTINE(LIST)
  735.                   A deprecated form of subroutine call.  See the
  736.                   _p_e_r_l_s_u_b manpage.
  737.  
  738.           do EXPR Uses the value of EXPR as a filename and executes
  739.                   the contents of the file as a Perl script.  Its
  740.                   primary use is to include subroutines from a Perl
  741.                   subroutine library.
  742.  
  743.                       do 'stat.pl';
  744.  
  745.                   is just like
  746.  
  747.                       eval `cat stat.pl`;
  748.  
  749.                   except that it's more efficient, more concise, keeps
  750.                   track of the current filename for error messages,
  751.                   and searches all the ----IIII libraries if the file isn't
  752.                   in the current directory (see also the @INC array in
  753.                   the section on _P_r_e_d_e_f_i_n_e_d _N_a_m_e_s in the _p_e_r_l_v_a_r
  754.                   manpage).  It's the same, however, in that it does
  755.                   reparse the file every time you call it, so you
  756.                   probably don't want to do this inside a loop.
  757.  
  758.                   Note that inclusion of library modules is better
  759.                   done with the _u_s_e() and _r_e_q_u_i_r_e() operators.
  760.  
  761.           dump LABEL
  762.                   This causes an immediate core dump.  Primarily this
  763.                   is so that you can use the uuuunnnndddduuuummmmpppp program to turn
  764.                   your core dump into an executable binary after
  765.                   having initialized all your variables at the
  766.                   beginning of the program.  When the new binary is
  767.                   executed it will begin by executing a goto LABEL
  768.                   (with all the restrictions that goto suffers).
  769.                   Think of it as a goto with an intervening core dump
  770.                   and reincarnation.  If LABEL is omitted, restarts
  771.                   the program from the top.  WARNING: any files opened
  772.                   at the time of the dump will NOT be open any more
  773.                   when the program is reincarnated, with possible
  774.                   resulting confusion on the part of Perl.  See also
  775.                   ----uuuu option in the _p_e_r_l_r_u_n manpage.
  776.  
  777.                   Example:
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.      Page 12                                         (printed 6/30/95)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  797.  
  798.  
  799.  
  800.                       #!/usr/bin/perl
  801.                       require 'getopt.pl';
  802.                       require 'stat.pl';
  803.                       %days = (
  804.                           'Sun' => 1,
  805.                           'Mon' => 2,
  806.                           'Tue' => 3,
  807.                           'Wed' => 4,
  808.                           'Thu' => 5,
  809.                           'Fri' => 6,
  810.                           'Sat' => 7,
  811.                       );
  812.  
  813.                       dump QUICKSTART if $ARGV[0] eq '-d';
  814.  
  815.                       QUICKSTART:
  816.                       Getopt('f');
  817.  
  818.  
  819.           each ASSOC_ARRAY
  820.                   Returns a 2 element array consisting of the key and
  821.                   value for the next value of an associative array, so
  822.                   that you can iterate over it.  Entries are returned
  823.                   in an apparently random order.  When the array is
  824.                   entirely read, a null array is returned (which when
  825.                   assigned produces a FALSE (0) value).  The next call
  826.                   to _e_a_c_h() after that will start iterating again.
  827.                   The iterator can be reset only by reading all the
  828.                   elements from the array.  You should not add
  829.                   elements to an array while you're iterating over it.
  830.                   There is a single iterator for each associative
  831.                   array, shared by all _e_a_c_h(), _k_e_y_s() and _v_a_l_u_e_s()
  832.                   function calls in the program.  The following prints
  833.                   out your environment like the _p_r_i_n_t_e_n_v(1) program,
  834.                   only in a different order:
  835.  
  836.                       while (($key,$value) = each %ENV) {
  837.                           print "$key=$value\n";
  838.                       }
  839.  
  840.                   See also _k_e_y_s() and _v_a_l_u_e_s().
  841.  
  842.           eof FILEHANDLE
  843.  
  844.           eof     Returns 1 if the next read on FILEHANDLE will return
  845.                   end of file, or if FILEHANDLE is not open.
  846.                   FILEHANDLE may be an expression whose value gives
  847.                   the real filehandle name.  (Note that this function
  848.                   actually reads a character and then _u_n_g_e_t_c()s it, so
  849.                   it is not very useful in an interactive context.)
  850.                   An eof without an argument returns the eof status
  851.                   for the last file read.  Empty parentheses () may be
  852.  
  853.  
  854.  
  855.      Page 13                                         (printed 6/30/95)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  863.  
  864.  
  865.  
  866.                   used to indicate the pseudo file formed of the files
  867.                   listed on the command line, i.e.  eof() is
  868.                   reasonable to use inside a while (<>) loop to detect
  869.                   the end of only the last file.  Use eof(ARGV) or eof
  870.                   without the parentheses to test _E_A_C_H file in a while
  871.                   (<>) loop.  Examples:
  872.  
  873.                       # insert dashes just before last line of last file
  874.                       while (<>) {
  875.                           if (eof()) {
  876.                               print "--------------\n";
  877.                           }
  878.                           print;
  879.                       }
  880.  
  881.                       # reset line numbering on each input file
  882.                       while (<>) {
  883.                           print "$.\t$_";
  884.                           if (eof) {      # Not eof().
  885.                               close(ARGV);
  886.                           }
  887.                       }
  888.  
  889.                   Practical hint: you almost never need to use eof in
  890.                   Perl, because the input operators return undef when
  891.                   they run out of data.
  892.  
  893.           eval EXPR
  894.  
  895.           eval BLOCK
  896.                   EXPR is parsed and executed as if it were a little
  897.                   Perl program.  It is executed in the context of the
  898.                   current Perl program, so that any variable settings,
  899.                   subroutine or format definitions remain afterwards.
  900.                   The value returned is the value of the last
  901.                   expression evaluated, or a return statement may be
  902.                   used, just as with subroutines.
  903.  
  904.                   If there is a syntax error or runtime error, or a
  905.                   _d_i_e() statement is executed, an undefined value is
  906.                   returned by _e_v_a_l(), and $@ is set to the error
  907.                   message.  If there was no error, $@ is guaranteed to
  908.                   be a null string.  If EXPR is omitted, evaluates $_.
  909.                   The final semicolon, if any, may be omitted from the
  910.                   expression.
  911.  
  912.                   Note that, since _e_v_a_l() traps otherwise-fatal
  913.                   errors, it is useful for determining whether a
  914.                   particular feature (such as _d_b_m_o_p_e_n() or _s_y_m_l_i_n_k())
  915.                   is implemented.  It is also Perl's exception
  916.                   trapping mechanism, where the die operator is used
  917.                   to raise exceptions.
  918.  
  919.  
  920.  
  921.      Page 14                                         (printed 6/30/95)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  929.  
  930.  
  931.  
  932.                   If the code to be executed doesn't vary, you may use
  933.                   the eval-BLOCK form to trap run-time errors without
  934.                   incurring the penalty of recompiling each time.  The
  935.                   error, if any, is still returned in $@.  Examples:
  936.  
  937.                       # make divide-by-zero non-fatal
  938.                       eval { $answer = $a / $b; }; warn $@ if $@;
  939.  
  940.                       # same thing, but less efficient
  941.                       eval '$answer = $a / $b'; warn $@ if $@;
  942.  
  943.                       # a compile-time error
  944.                       eval { $answer = };
  945.  
  946.                       # a run-time error
  947.                       eval '$answer =';   # sets $@
  948.  
  949.                   With an _e_v_a_l(), you should be especially careful to
  950.                   remember what's being looked at when:
  951.  
  952.                       eval $x;            # CASE 1
  953.                       eval "$x";          # CASE 2
  954.  
  955.                       eval '$x';          # CASE 3
  956.                       eval { $x };        # CASE 4
  957.  
  958.                       eval "\$$x++"       # CASE 5
  959.                       $$x++;              # CASE 6
  960.  
  961.                   Cases 1 and 2 above behave identically: they run the
  962.                   code contained in the variable $x.  (Although case 2
  963.                   has misleading double quotes making the reader
  964.                   wonder what else might be happening (nothing is).)
  965.                   Cases 3 and 4 likewise behave in the same way: they
  966.                   run the code <$x>, which does nothing at all.  (Case
  967.                   4 is preferred for purely visual reasons.) Case 5 is
  968.                   a place where normally you _W_O_U_L_D like to use double
  969.                   quotes, except that in particular situation, you can
  970.                   just use symbolic references instead, as in case 6.
  971.  
  972.           exec LIST
  973.                   The _e_x_e_c() function executes a system command _A_N_D
  974.                   _N_E_V_E_R _R_E_T_U_R_N_S.  Use the _s_y_s_t_e_m() function if you
  975.                   want it to return.
  976.  
  977.                   If there is more than one argument in LIST, or if
  978.                   LIST is an array with more than one value, calls
  979.                   _e_x_e_c_v_p(3) with the arguments in LIST.  If there is
  980.                   only one scalar argument, the argument is checked
  981.                   for shell metacharacters.  If there are any, the
  982.                   entire argument is passed to /bin/sh -c for parsing.
  983.                   If there are none, the argument is split into words
  984.  
  985.  
  986.  
  987.      Page 15                                         (printed 6/30/95)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  995.  
  996.  
  997.  
  998.                   and passed directly to _e_x_e_c_v_p(), which is more
  999.                   efficient.  Note: _e_x_e_c() (and _s_y_s_t_e_m(0) do not flush
  1000.                   your output buffer, so you may need to set $| to
  1001.                   avoid lost output.  Examples:
  1002.  
  1003.                       exec '/bin/echo', 'Your arguments are: ', @ARGV;
  1004.                       exec "sort $outfile | uniq";
  1005.  
  1006.                   If you don't really want to execute the first
  1007.                   argument, but want to lie to the program you are
  1008.                   executing about its own name, you can specify the
  1009.                   program you actually want to run as an "indirect
  1010.                   object" (without a comma) in front of the LIST.
  1011.                   (This always forces interpretation of the LIST as a
  1012.                   multi-valued list, even if there is only a single
  1013.                   scalar in the list.)  Example:
  1014.  
  1015.                       $shell = '/bin/csh';
  1016.                       exec $shell '-sh';          # pretend it's a login shell
  1017.  
  1018.                   or, more directly,
  1019.  
  1020.                       exec {'/bin/csh'} '-sh';    # pretend it's a login shell
  1021.  
  1022.  
  1023.           exists EXPR
  1024.                   Returns TRUE if the specified hash key exists in its
  1025.                   hash array, even if the corresponding value is
  1026.                   undefined.
  1027.  
  1028.                       print "Exists\n" if exists $array{$key};
  1029.                       print "Defined\n" if defined $array{$key};
  1030.                       print "True\n" if $array{$key};
  1031.  
  1032.                   A hash element can only be TRUE if it's defined, and
  1033.                   defined if it exists, but the reverse doesn't
  1034.                   necessarily hold true.
  1035.  
  1036.                   Note that the EXPR can be arbitrarily complicated as
  1037.                   long as the final operation is a hash key lookup:
  1038.  
  1039.                       if (exists $ref->[$x][$y]{$key}) { ... }
  1040.  
  1041.  
  1042.           exit EXPR
  1043.                   Evaluates EXPR and exits immediately with that
  1044.                   value.  (Actually, it calls any defined END routines
  1045.                   first, but the END routines may not abort the exit.
  1046.                   Likewise any object destructors that need to be
  1047.                   called are called before exit.)  Example:
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.      Page 16                                         (printed 6/30/95)
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1061.  
  1062.  
  1063.  
  1064.                       $ans = <STDIN>;
  1065.                       exit 0 if $ans =~ /^[Xx]/;
  1066.  
  1067.                   See also _d_i_e().  If EXPR is omitted, exits with 0
  1068.                   status.
  1069.  
  1070.           exp EXPR
  1071.                   Returns _e (the natural logarithm base) to the power
  1072.                   of EXPR. If EXPR is omitted, gives exp($_).
  1073.  
  1074.           fcntl FILEHANDLE,FUNCTION,SCALAR
  1075.                   Implements the _f_c_n_t_l(2) function.  You'll probably
  1076.                   have to say
  1077.  
  1078.                       use Fcntl;
  1079.  
  1080.                   first to get the correct function definitions.
  1081.                   Argument processing and value return works just like
  1082.                   _i_o_c_t_l() below.  Note that _f_c_n_t_l() will produce a
  1083.                   fatal error if used on a machine that doesn't
  1084.                   implement _f_c_n_t_l(2).  For example:
  1085.  
  1086.                       use Fcntl;
  1087.                       fcntl($filehandle, F_GETLK, $packed_return_buffer);
  1088.  
  1089.  
  1090.           fileno FILEHANDLE
  1091.                   Returns the file descriptor for a filehandle.  This
  1092.                   is useful for constructing bitmaps for _s_e_l_e_c_t().  If
  1093.                   FILEHANDLE is an expression, the value is taken as
  1094.                   the name of the filehandle.
  1095.  
  1096.           flock FILEHANDLE,OPERATION
  1097.                   Calls _f_l_o_c_k(2) on FILEHANDLE.  See the _f_l_o_c_k(_2)
  1098.                   manpage for definition of OPERATION.  Returns TRUE
  1099.                   for success, FALSE on failure.  Will produce a fatal
  1100.                   error if used on a machine that doesn't implement
  1101.                   _f_l_o_c_k(2).  Here's a mailbox appender for BSD
  1102.                   systems.
  1103.  
  1104.                       $LOCK_SH = 1;
  1105.                       $LOCK_EX = 2;
  1106.                       $LOCK_NB = 4;
  1107.                       $LOCK_UN = 8;
  1108.  
  1109.                       sub lock {
  1110.                           flock(MBOX,$LOCK_EX);
  1111.                           # and, in case someone appended
  1112.                           # while we were waiting...
  1113.                           seek(MBOX, 0, 2);
  1114.                       }
  1115.  
  1116.  
  1117.  
  1118.  
  1119.      Page 17                                         (printed 6/30/95)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1127.  
  1128.  
  1129.  
  1130.                       sub unlock {
  1131.                           flock(MBOX,$LOCK_UN);
  1132.                       }
  1133.  
  1134.                       open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
  1135.                               or die "Can't open mailbox: $!";
  1136.  
  1137.                       lock();
  1138.                       print MBOX $msg,"\n\n";
  1139.                       unlock();
  1140.  
  1141.                   Note that _f_l_o_c_k() can't lock things over the
  1142.                   network.  You need to do locking with _f_c_n_t_l() for
  1143.                   that.
  1144.  
  1145.           fork    Does a _f_o_r_k(2) system call.  Returns the child pid
  1146.                   to the parent process and 0 to the child process, or
  1147.                   undef if the fork is unsuccessful.  Note: unflushed
  1148.                   buffers remain unflushed in both processes, which
  1149.                   means you may need to set $| ($AUTOFLUSH in English)
  1150.                   or call the _a_u_t_o_f_l_u_s_h() FileHandle method to avoid
  1151.                   duplicate output.
  1152.  
  1153.                   If you _f_o_r_k() without ever waiting on your children,
  1154.                   you will accumulate zombies:
  1155.  
  1156.                       $SIG{'CHLD'} = sub { wait };
  1157.  
  1158.                   There's also the double-fork trick (error checking
  1159.                   on _f_o_r_k() returns omitted);
  1160.  
  1161.                       unless ($pid = fork) {
  1162.                           unless (fork) {
  1163.                               exec "what you really wanna do";
  1164.                               die "no exec";
  1165.                               # ... or ...
  1166.                               some_perl_code_here;
  1167.                               exit 0;
  1168.                           }
  1169.                           exit 0;
  1170.                       }
  1171.                       waitpid($pid,0);
  1172.  
  1173.  
  1174.           formline PICTURE, LIST
  1175.                   This is an internal function used by formats, though
  1176.                   you may call it too.  It formats (see the _p_e_r_l_f_o_r_m
  1177.                   manpage) a list of values according to the contents
  1178.                   of PICTURE, placing the output into the format
  1179.                   output accumulator, $^A.  Eventually, when a _w_r_i_t_e()
  1180.                   is done, the contents of $^A are written to some
  1181.                   filehandle, but you could also read $^A yourself and
  1182.  
  1183.  
  1184.  
  1185.      Page 18                                         (printed 6/30/95)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1193.  
  1194.  
  1195.  
  1196.                   then set $^A back to "".  Note that a format
  1197.                   typically does one _f_o_r_m_l_i_n_e() per line of form, but
  1198.                   the _f_o_r_m_l_i_n_e() function itself doesn't care how many
  1199.                   newlines are embedded in the PICTURE.  Be careful if
  1200.                   you put double quotes around the picture, since an
  1201.                   "@" character may be taken to mean the beginning of
  1202.                   an array name.  _f_o_r_m_l_i_n_e() always returns TRUE.
  1203.  
  1204.           getc FILEHANDLE
  1205.  
  1206.           getc    Returns the next character from the input file
  1207.                   attached to FILEHANDLE, or a null string at end of
  1208.                   file.  If FILEHANDLE is omitted, reads from STDIN.
  1209.  
  1210.           getlogin
  1211.                   Returns the current login from /_e_t_c/_u_t_m_p, if any.
  1212.                   If null, use _g_e_t_p_w_u_i_d().
  1213.  
  1214.                       $login = getlogin || (getpwuid($<))[0] || "Kilroy";
  1215.  
  1216.  
  1217.           getpeername SOCKET
  1218.                   Returns the packed sockaddr address of other end of
  1219.                   the SOCKET connection.
  1220.  
  1221.                       # An internet sockaddr
  1222.                       $sockaddr = 'S n a4 x8';
  1223.                       $hersockaddr = getpeername(S);
  1224.                       ($family, $port, $heraddr) = unpack($sockaddr,$hersockaddr);
  1225.  
  1226.  
  1227.           getpgrp PID
  1228.                   Returns the current process group for the specified
  1229.                   PID, 0 for the current process.  Will produce a
  1230.                   fatal error if used on a machine that doesn't
  1231.                   implement _g_e_t_p_g_r_p(2).  If PID is omitted, returns
  1232.                   process group of current process.
  1233.  
  1234.           getppid Returns the process id of the parent process.
  1235.  
  1236.           getpriority WHICH,WHO
  1237.                   Returns the current priority for a process, a
  1238.                   process group, or a user.  (See the _g_e_t_p_r_i_o_r_i_t_y(_2)
  1239.                   manpage.)  Will produce a fatal error if used on a
  1240.                   machine that doesn't implement _g_e_t_p_r_i_o_r_i_t_y(2).
  1241.  
  1242.           getpwnam NAME
  1243.  
  1244.           getgrnam NAME
  1245.  
  1246.           gethostbyname NAME
  1247.  
  1248.  
  1249.  
  1250.  
  1251.      Page 19                                         (printed 6/30/95)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1259.  
  1260.  
  1261.  
  1262.           getnetbyname NAME
  1263.  
  1264.           getprotobyname NAME
  1265.  
  1266.           getpwuid UID
  1267.  
  1268.           getgrgid GID
  1269.  
  1270.           getservbyname NAME,PROTO
  1271.  
  1272.           gethostbyaddr ADDR,ADDRTYPE
  1273.  
  1274.           getnetbyaddr ADDR,ADDRTYPE
  1275.  
  1276.           getprotobynumber NUMBER
  1277.  
  1278.           getservbyport PORT,PROTO
  1279.  
  1280.           getpwent
  1281.  
  1282.           getgrent
  1283.  
  1284.           gethostent
  1285.  
  1286.           getnetent
  1287.  
  1288.           getprotoent
  1289.  
  1290.           getservent
  1291.  
  1292.           setpwent
  1293.  
  1294.           setgrent
  1295.  
  1296.           sethostent STAYOPEN
  1297.  
  1298.           setnetent STAYOPEN
  1299.  
  1300.           setprotoent STAYOPEN
  1301.  
  1302.           setservent STAYOPEN
  1303.  
  1304.           endpwent
  1305.  
  1306.           endgrent
  1307.  
  1308.           endhostent
  1309.  
  1310.           endnetent
  1311.  
  1312.           endprotoent
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20                                         (printed 6/30/95)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1325.  
  1326.  
  1327.  
  1328.           endservent
  1329.                   These routines perform the same functions as their
  1330.                   counterparts in the system library.  Within a list
  1331.                   context, the return values from the various get
  1332.                   routines are as follows:
  1333.  
  1334.                       ($name,$passwd,$uid,$gid,
  1335.                          $quota,$comment,$gcos,$dir,$shell) = getpw*
  1336.                       ($name,$passwd,$gid,$members) = getgr*
  1337.                       ($name,$aliases,$addrtype,$length,@addrs) = gethost*
  1338.                       ($name,$aliases,$addrtype,$net) = getnet*
  1339.                       ($name,$aliases,$proto) = getproto*
  1340.                       ($name,$aliases,$port,$proto) = getserv*
  1341.  
  1342.                   (If the entry doesn't exist you get a null list.)
  1343.  
  1344.                   Within a scalar context, you get the name, unless
  1345.                   the function was a lookup by name, in which case you
  1346.                   get the other thing, whatever it is.  (If the entry
  1347.                   doesn't exist you get the undefined value.)  For
  1348.                   example:
  1349.  
  1350.                       $uid = getpwnam
  1351.                       $name = getpwuid
  1352.                       $name = getpwent
  1353.                       $gid = getgrnam
  1354.                       $name = getgrgid
  1355.                       $name = getgrent
  1356.                       etc.
  1357.  
  1358.                   The $members value returned by _g_e_t_g_r*() is a space
  1359.                   separated list of the login names of the members of
  1360.                   the group.
  1361.  
  1362.                   For the _g_e_t_h_o_s_t*() functions, if the h_errno
  1363.                   variable is supported in C, it will be returned to
  1364.                   you via $? if the function call fails.  The @addrs
  1365.                   value returned by a successful call is a list of the
  1366.                   raw addresses returned by the corresponding system
  1367.                   library call.  In the Internet domain, each address
  1368.                   is four bytes long and you can unpack it by saying
  1369.                   something like:
  1370.  
  1371.                       ($a,$b,$c,$d) = unpack('C4',$addr[0]);
  1372.  
  1373.  
  1374.           getsockname SOCKET
  1375.                   Returns the packed sockaddr address of this end of
  1376.                   the SOCKET connection.
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.      Page 21                                         (printed 6/30/95)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1391.  
  1392.  
  1393.  
  1394.                       # An internet sockaddr
  1395.                       $sockaddr = 'S n a4 x8';
  1396.                       $mysockaddr = getsockname(S);
  1397.                       ($family, $port, $myaddr) =
  1398.                                       unpack($sockaddr,$mysockaddr);
  1399.  
  1400.  
  1401.           getsockopt SOCKET,LEVEL,OPTNAME
  1402.                   Returns the socket option requested, or undefined if
  1403.                   there is an error.
  1404.  
  1405.           glob EXPR
  1406.                   Returns the value of EXPR with filename expansions
  1407.                   such as a shell would do.  This is the internal
  1408.                   function implementing the <*.*> operator.
  1409.  
  1410.           gmtime EXPR
  1411.                   Converts a time as returned by the time function to
  1412.                   a 9-element array with the time analyzed for the
  1413.                   Greenwich timezone.  Typically used as follows:
  1414.  
  1415.                       ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  1416.                                                               gmtime(time);
  1417.  
  1418.                   All array elements are numeric, and come straight
  1419.                   out of a struct tm.  In particular this means that
  1420.                   $mon has the range 0..11 and $wday has the range
  1421.                   0..6.  If EXPR is omitted, does gmtime(time()).
  1422.  
  1423.           goto LABEL
  1424.  
  1425.           goto &NAME
  1426.                   The goto-LABEL form finds the statement labeled with
  1427.                   LABEL and resumes execution there.  It may not be
  1428.                   used to go into any construct that requires
  1429.                   initialization, such as a subroutine or a foreach
  1430.                   loop.  It also can't be used to go into a construct
  1431.                   that is optimized away.  It can be used to go almost
  1432.                   anywhere else within the dynamic scope, including
  1433.                   out of subroutines, but it's usually better to use
  1434.                   some other construct such as last or die.  The
  1435.                   author of Perl has never felt the need to use this
  1436.                   form of goto (in Perl, that is--C is another
  1437.                   matter).
  1438.  
  1439.                   The goto-&NAME form is highly magical, and
  1440.                   substitutes a call to the named subroutine for the
  1441.                   currently running subroutine.  This is used by
  1442.                   AUTOLOAD subroutines that wish to load another
  1443.                   subroutine and then pretend that the other
  1444.                   subroutine had been called in the first place
  1445.                   (except that any modifications to @_ in the current
  1446.  
  1447.  
  1448.  
  1449.      Page 22                                         (printed 6/30/95)
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1457.  
  1458.  
  1459.  
  1460.                   subroutine are propagated to the other subroutine.)
  1461.                   After the goto, not even _c_a_l_l_e_r() will be able to
  1462.                   tell that this routine was called first.
  1463.  
  1464.           grep BLOCK LIST
  1465.  
  1466.           grep EXPR,LIST
  1467.                   Evaluates the BLOCK or EXPR for each element of LIST
  1468.                   (locally setting $_ to each element) and returns the
  1469.                   list value consisting of those elements for which
  1470.                   the expression evaluated to TRUE.  In a scalar
  1471.                   context, returns the number of times the expression
  1472.                   was TRUE.
  1473.  
  1474.                       @foo = grep(!/^#/, @bar);    # weed out comments
  1475.  
  1476.                   or equivalently,
  1477.  
  1478.                       @foo = grep {!/^#/} @bar;    # weed out comments
  1479.  
  1480.                   Note that, since $_ is a reference into the list
  1481.                   value, it can be used to modify the elements of the
  1482.                   array.  While this is useful and supported, it can
  1483.                   cause bizarre results if the LIST is not a named
  1484.                   array.
  1485.  
  1486.           hex EXPR
  1487.                   Returns the decimal value of EXPR interpreted as an
  1488.                   hex string.  (To interpret strings that might start
  1489.                   with 0 or 0x see _o_c_t().)  If EXPR is omitted, uses
  1490.                   $_.
  1491.  
  1492.           import  There is no built-in _i_m_p_o_r_t() function.  It is
  1493.                   merely an ordinary method subroutine defined (or
  1494.                   inherited) by modules that wish to export names to
  1495.                   another module.  The _u_s_e() function calls the
  1496.                   _i_m_p_o_r_t() method for the package used.  See also the
  1497.                   use entry elsewhere in this documentbelow and the
  1498.                   _p_e_r_l_m_o_d manpage.
  1499.  
  1500.           index STR,SUBSTR,POSITION
  1501.  
  1502.           index STR,SUBSTR
  1503.                   Returns the position of the first occurrence of
  1504.                   SUBSTR in STR at or after POSITION.  If POSITION is
  1505.                   omitted, starts searching from the beginning of the
  1506.                   string.  The return value is based at 0, or whatever
  1507.                   you've set the $[ variable to.  If the substring is
  1508.                   not found, returns one less than the base,
  1509.                   ordinarily -1.
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.      Page 23                                         (printed 6/30/95)
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1523.  
  1524.  
  1525.  
  1526.           int EXPR
  1527.                   Returns the integer portion of EXPR.  If EXPR is
  1528.                   omitted, uses $_.
  1529.  
  1530.           ioctl FILEHANDLE,FUNCTION,SCALAR
  1531.                   Implements the _i_o_c_t_l(2) function.  You'll probably
  1532.                   have to say
  1533.  
  1534.                       require "ioctl.ph"; # probably /usr/local/lib/perl/ioctl.ph
  1535.  
  1536.                   first to get the correct function definitions.  If
  1537.                   ioctl.ph doesn't exist or doesn't have the correct
  1538.                   definitions you'll have to roll your own, based on
  1539.                   your C header files such as <sys/ioctl.h>.  (There
  1540.                   is a Perl script called hhhh2222pppphhhh that comes with the
  1541.                   Perl kit which may help you in this.)  SCALAR will
  1542.                   be read and/or written depending on the FUNCTION--a
  1543.                   pointer to the string value of SCALAR will be passed
  1544.                   as the third argument of the actual ioctl call.  (If
  1545.                   SCALAR has no string value but does have a numeric
  1546.                   value, that value will be passed rather than a
  1547.                   pointer to the string value.  To guarantee this to
  1548.                   be TRUE, add a 0 to the scalar before using it.)
  1549.                   The _p_a_c_k() and _u_n_p_a_c_k() functions are useful for
  1550.                   manipulating the values of structures used by
  1551.                   _i_o_c_t_l().  The following example sets the erase
  1552.                   character to DEL.
  1553.  
  1554.                       require 'ioctl.ph';
  1555.                       $sgttyb_t = "ccccs";                # 4 chars and a short
  1556.                       if (ioctl(STDIN,$TIOCGETP,$sgttyb)) {
  1557.                           @ary = unpack($sgttyb_t,$sgttyb);
  1558.                           $ary[2] = 127;
  1559.                           $sgttyb = pack($sgttyb_t,@ary);
  1560.                           ioctl(STDIN,$TIOCSETP,$sgttyb)
  1561.                               || die "Can't ioctl: $!";
  1562.                       }
  1563.  
  1564.                   The return value of ioctl (and fcntl) is as follows:
  1565.  
  1566.                           if OS returns:          then Perl returns:
  1567.                               -1                    undefined value
  1568.                                0                  string "0 but true"
  1569.                           anything else               that number
  1570.  
  1571.                   Thus Perl returns TRUE on success and FALSE on
  1572.                   failure, yet you can still easily determine the
  1573.                   actual value returned by the operating system:
  1574.  
  1575.                       ($retval = ioctl(...)) || ($retval = -1);
  1576.                       printf "System returned %d\n", $retval;
  1577.  
  1578.  
  1579.  
  1580.  
  1581.      Page 24                                         (printed 6/30/95)
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1589.  
  1590.  
  1591.  
  1592.           join EXPR,LIST
  1593.                   Joins the separate strings of LIST or ARRAY into a
  1594.                   single string with fields separated by the value of
  1595.                   EXPR, and returns the string.  Example:
  1596.  
  1597.                       $_ = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
  1598.  
  1599.                   See the split entry in the _p_e_r_l_f_u_n_c manpage.
  1600.  
  1601.           keys ASSOC_ARRAY
  1602.                   Returns a normal array consisting of all the keys of
  1603.                   the named associative array.  (In a scalar context,
  1604.                   returns the number of keys.) The keys are returned
  1605.                   in an apparently random order, but it is the same
  1606.                   order as either the _v_a_l_u_e_s() or _e_a_c_h() function
  1607.                   produces (given that the associative array has not
  1608.                   been modified).  Here is yet another way to print
  1609.                   your environment:
  1610.  
  1611.                       @keys = keys %ENV;
  1612.                       @values = values %ENV;
  1613.                       while ($#keys >= 0) {
  1614.                           print pop(@keys), '=', pop(@values), "\n";
  1615.                       }
  1616.  
  1617.                   or how about sorted by key:
  1618.  
  1619.                       foreach $key (sort(keys %ENV)) {
  1620.                           print $key, '=', $ENV{$key}, "\n";
  1621.                       }
  1622.  
  1623.  
  1624.           kill LIST
  1625.                   Sends a signal to a list of processes.  The first
  1626.                   element of the list must be the signal to send.
  1627.                   Returns the number of processes successfully
  1628.                   signaled.
  1629.  
  1630.                       $cnt = kill 1, $child1, $child2;
  1631.                       kill 9, @goners;
  1632.  
  1633.                   Unlike in the shell, in Perl if the _S_I_G_N_A_L is
  1634.                   negative, it kills process groups instead of
  1635.                   processes.  (On System V, a negative _P_R_O_C_E_S_S number
  1636.                   will also kill process groups, but that's not
  1637.                   portable.)  That means you usually want to use
  1638.                   positive not negative signals.  You may also use a
  1639.                   signal name in quotes.
  1640.  
  1641.           last LABEL
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.      Page 25                                         (printed 6/30/95)
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1655.  
  1656.  
  1657.  
  1658.           last    The last command is like the break statement in C
  1659.                   (as used in loops); it immediately exits the loop in
  1660.                   question.  If the LABEL is omitted, the command
  1661.                   refers to the innermost enclosing loop.  The
  1662.                   continue block, if any, is not executed:
  1663.  
  1664.                       line: while (<STDIN>) {
  1665.                           last line if /^$/;      # exit when done with header
  1666.                           ...
  1667.                       }
  1668.  
  1669.  
  1670.           lc EXPR Returns an lowercased version of EXPR.  This is the
  1671.                   internal function implementing the \L escape in
  1672.                   double-quoted strings.
  1673.  
  1674.           lcfirst EXPR
  1675.                   Returns the value of EXPR with the first character
  1676.                   lowercased.  This is the internal function
  1677.                   implementing the \l escape in double-quoted strings.
  1678.  
  1679.           length EXPR
  1680.                   Returns the length in characters of the value of
  1681.                   EXPR.  If EXPR is omitted, returns length of $_.
  1682.  
  1683.           link OLDFILE,NEWFILE
  1684.                   Creates a new filename linked to the old filename.
  1685.                   Returns 1 for success, 0 otherwise.
  1686.  
  1687.           listen SOCKET,QUEUESIZE
  1688.                   Does the same thing that the listen system call
  1689.                   does.  Returns TRUE if it succeeded, FALSE
  1690.                   otherwise.  See example in the _p_e_r_l_i_p_c manpage.
  1691.  
  1692.           local EXPR
  1693.                   In general, you should be using "my" instead of
  1694.                   "local", because it's faster and safer.  Format
  1695.                   variables have to use "local" though, as do any
  1696.                   other variables whose local value must be visible to
  1697.                   called subroutines.  This is known as dynamic
  1698.                   scoping.  Lexical scoping is done with "my", which
  1699.                   works more like C's auto declarations.
  1700.  
  1701.                   A local modifies the listed variables to be local to
  1702.                   the enclosing block, subroutine, eval or "do".  If
  1703.                   more than one value is listed, the list must be
  1704.                   placed in parens.  All the listed elements must be
  1705.                   legal lvalues.  This operator works by saving the
  1706.                   current values of those variables in LIST on a
  1707.                   hidden stack and restoring them upon exiting the
  1708.                   block, subroutine or eval.  This means that called
  1709.                   subroutines can also reference the local variable,
  1710.  
  1711.  
  1712.  
  1713.      Page 26                                         (printed 6/30/95)
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1721.  
  1722.  
  1723.  
  1724.                   but not the global one.  The LIST may be assigned to
  1725.                   if desired, which allows you to initialize your
  1726.                   local variables.  (If no initializer is given for a
  1727.                   particular variable, it is created with an undefined
  1728.                   value.)  Commonly this is used to name the
  1729.                   parameters to a subroutine.  Examples:
  1730.  
  1731.                       sub RANGEVAL {
  1732.                           local($min, $max, $thunk) = @_;
  1733.                           local $result = '';
  1734.                           local $i;
  1735.  
  1736.                           # Presumably $thunk makes reference to $i
  1737.  
  1738.                           for ($i = $min; $i < $max; $i++) {
  1739.                               $result .= eval $thunk;
  1740.                           }
  1741.  
  1742.                           $result;
  1743.                       }
  1744.  
  1745.                       if ($sw eq '-v') {
  1746.                           # init local array with global array
  1747.                           local @ARGV = @ARGV;
  1748.                           unshift(@ARGV,'echo');
  1749.                           system @ARGV;
  1750.                       }
  1751.                       # @ARGV restored
  1752.  
  1753.                       # temporarily add to digits associative array
  1754.                       if ($base12) {
  1755.                           # (NOTE: not claiming this is efficient!)
  1756.                           local(%digits) = (%digits,'t',10,'e',11);
  1757.                           parse_num();
  1758.                       }
  1759.  
  1760.                   Note that _l_o_c_a_l() is a run-time command, and so gets
  1761.                   executed every time through a loop.  In Perl 4 it
  1762.                   used  up more stack storage each time until the loop
  1763.                   was exited.  Perl 5 reclaims the space each time
  1764.                   through, but it's still more efficient to declare
  1765.                   your variables outside the loop.
  1766.  
  1767.                   When you assign to a localized EXPR, the local
  1768.                   doesn't change whether EXPR is viewed as a scalar or
  1769.                   an array.  So
  1770.  
  1771.                       local($foo) = <STDIN>;
  1772.                       local @FOO = <STDIN>;
  1773.  
  1774.                   both supply a list context to the righthand side,
  1775.                   while
  1776.  
  1777.  
  1778.  
  1779.      Page 27                                         (printed 6/30/95)
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1787.  
  1788.  
  1789.  
  1790.                       local $foo = <STDIN>;
  1791.  
  1792.                   supplies a scalar context.
  1793.  
  1794.           localtime EXPR
  1795.                   Converts a time as returned by the time function to
  1796.                   a 9-element array with the time analyzed for the
  1797.                   local timezone.  Typically used as follows:
  1798.  
  1799.                       ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  1800.                                                                   localtime(time);
  1801.  
  1802.                   All array elements are numeric, and come straight
  1803.                   out of a struct tm.  In particular this means that
  1804.                   $mon has the range 0..11 and $wday has the range
  1805.                   0..6.  If EXPR is omitted, does _l_o_c_a_l_t_i_m_e(time).
  1806.  
  1807.                   In a scalar context, prints out the _c_t_i_m_e(3) value:
  1808.  
  1809.                       $now_string = localtime;  # e.g. "Thu Oct 13 04:54:34 1994"
  1810.  
  1811.                   See also the timelocal entry in the _p_e_r_l_m_o_d manpage
  1812.                   and the _s_t_r_f_t_i_m_e(3) function available via the POSIX
  1813.                   modulie.
  1814.  
  1815.           log EXPR
  1816.                   Returns logarithm (base _e) of EXPR.  If EXPR is
  1817.                   omitted, returns log of $_.
  1818.  
  1819.           lstat FILEHANDLE
  1820.  
  1821.           lstat EXPR
  1822.                   Does the same thing as the _s_t_a_t() function, but
  1823.                   stats a symbolic link instead of the file the
  1824.                   symbolic link points to.  If symbolic links are
  1825.                   unimplemented on your system, a normal _s_t_a_t() is
  1826.                   done.
  1827.  
  1828.           m//     The match operator.  See the _p_e_r_l_o_p manpage.
  1829.  
  1830.           map BLOCK LIST
  1831.  
  1832.           map EXPR,LIST
  1833.                   Evaluates the BLOCK or EXPR for each element of LIST
  1834.                   (locally setting $_ to each element) and returns the
  1835.                   list value composed of the results of each such
  1836.                   evaluation.  Evaluates BLOCK or EXPR in a list
  1837.                   context, so each element of LIST may produce zero,
  1838.                   one, or more elements in the returned value.
  1839.  
  1840.                       @chars = map(chr, @nums);
  1841.  
  1842.  
  1843.  
  1844.  
  1845.      Page 28                                         (printed 6/30/95)
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1853.  
  1854.  
  1855.  
  1856.                   translates a list of numbers to the corresponding
  1857.                   characters.  And
  1858.  
  1859.                       %hash = map {&key($_), $_} @array;
  1860.  
  1861.                   is just a funny way to write
  1862.  
  1863.                       %hash = ();
  1864.                       foreach $_ (@array) {
  1865.                           $hash{&key($_)} = $_;
  1866.                       }
  1867.  
  1868.  
  1869.           mkdir FILENAME,MODE
  1870.                   Creates the directory specified by FILENAME, with
  1871.                   permissions specified by MODE (as modified by
  1872.                   umask).  If it succeeds it returns 1, otherwise it
  1873.                   returns 0 and sets $! (errno).
  1874.  
  1875.           msgctl ID,CMD,ARG
  1876.                   Calls the System V IPC function msgctl.  If CMD is
  1877.                   &IPC_STAT, then ARG must be a variable which will
  1878.                   hold the returned msqid_ds structure.  Returns like
  1879.                   ioctl: the undefined value for error, "0 but true"
  1880.                   for zero, or the actual return value otherwise.
  1881.  
  1882.           msgget KEY,FLAGS
  1883.                   Calls the System V IPC function msgget.  Returns the
  1884.                   message queue id, or the undefined value if there is
  1885.                   an error.
  1886.  
  1887.           msgsnd ID,MSG,FLAGS
  1888.                   Calls the System V IPC function msgsnd to send the
  1889.                   message MSG to the message queue ID.  MSG must begin
  1890.                   with the long integer message type, which may be
  1891.                   created with pack("L", $type).  Returns TRUE if
  1892.                   successful, or FALSE if there is an error.
  1893.  
  1894.           msgrcv ID,VAR,SIZE,TYPE,FLAGS
  1895.                   Calls the System V IPC function msgrcv to receive a
  1896.                   message from message queue ID into variable VAR with
  1897.                   a maximum message size of SIZE.  Note that if a
  1898.                   message is received, the message type will be the
  1899.                   first thing in VAR, and the maximum length of VAR is
  1900.                   SIZE plus the size of the message type.  Returns
  1901.                   TRUE if successful, or FALSE if there is an error.
  1902.  
  1903.           my EXPR A "my" declares the listed variables to be local
  1904.                   (lexically) to the enclosing block, subroutine, eval
  1905.                   or "do".  If more than one value is listed, the list
  1906.                   must be placed in parens.  All the listed elements
  1907.                   must be legal lvalues.  Only alphanumeric
  1908.  
  1909.  
  1910.  
  1911.      Page 29                                         (printed 6/30/95)
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1919.  
  1920.  
  1921.  
  1922.                   identifiers may be lexically scoped--magical
  1923.                   builtins like $/ must be localized with "local"
  1924.                   instead.  In particular, you're not allowed to say
  1925.  
  1926.                       my $_;      # Illegal.
  1927.  
  1928.                   Unlike the "local" declaration, variables declared
  1929.                   with "my" are totally hidden from the outside world,
  1930.                   including any called subroutines (even if it's the
  1931.                   same subroutine--every call gets its own copy).
  1932.  
  1933.                   (An _e_v_a_l(), however, can see the lexical variables
  1934.                   of the scope it is being evaluated in so long as the
  1935.                   names aren't hidden by declarations within the
  1936.                   _e_v_a_l() itself.  See the _p_e_r_l_r_e_f manpage.)
  1937.  
  1938.                   The EXPR may be assigned to if desired, which allows
  1939.                   you to initialize your variables.  (If no
  1940.                   initializer is given for a particular variable, it
  1941.                   is created with an undefined value.)  Commonly this
  1942.                   is used to name the parameters to a subroutine.
  1943.                   Examples:
  1944.  
  1945.                       sub RANGEVAL {
  1946.                           my($min, $max, $thunk) = @_;
  1947.                           my $result = '';
  1948.                           my $i;
  1949.  
  1950.                           # Presumably $thunk makes reference to $i
  1951.  
  1952.                           for ($i = $min; $i < $max; $i++) {
  1953.                               $result .= eval $thunk;
  1954.                           }
  1955.  
  1956.                           $result;
  1957.                       }
  1958.  
  1959.                       if ($sw eq '-v') {
  1960.                           # init my array with global array
  1961.                           my @ARGV = @ARGV;
  1962.                           unshift(@ARGV,'echo');
  1963.                           system @ARGV;
  1964.                       }
  1965.                       # Outer @ARGV again visible
  1966.  
  1967.                   When you assign to the EXPR, the "my" doesn't change
  1968.                   whether EXPR is viewed as a scalar or an array.  So
  1969.  
  1970.                       my($foo) = <STDIN>;
  1971.                       my @FOO = <STDIN>;
  1972.  
  1973.                   both supply a list context to the righthand side,
  1974.  
  1975.  
  1976.  
  1977.      Page 30                                         (printed 6/30/95)
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  1985.  
  1986.  
  1987.  
  1988.                   while
  1989.  
  1990.                       my $foo = <STDIN>;
  1991.  
  1992.                   supplies a scalar context.
  1993.  
  1994.                   Some users may wish to encourage the use of
  1995.                   lexically scoped variables.  As an aid to catching
  1996.                   implicit references to package variables, if you say
  1997.  
  1998.                       use strict 'vars';
  1999.  
  2000.                   then any variable reference from there to the end of
  2001.                   the enclosing block must either refer to a lexical
  2002.                   variable, or must be fully qualified with the
  2003.                   package name.  A compilation error results
  2004.                   otherwise.  An inner block may countermand this with
  2005.                   "no strict 'vars'".
  2006.  
  2007.           next LABEL
  2008.  
  2009.           next    The next command is like the continue statement in
  2010.                   C; it starts the next iteration of the loop:
  2011.  
  2012.                       line: while (<STDIN>) {
  2013.                           next line if /^#/;      # discard comments
  2014.                           ...
  2015.                       }
  2016.  
  2017.                   Note that if there were a continue block on the
  2018.                   above, it would get executed even on discarded
  2019.                   lines.  If the LABEL is omitted, the command refers
  2020.                   to the innermost enclosing loop.
  2021.  
  2022.           no Module LIST
  2023.                   See the "use" function, which "no" is the opposite
  2024.                   of.
  2025.  
  2026.           oct EXPR
  2027.                   Returns the decimal value of EXPR interpreted as an
  2028.                   octal string.  (If EXPR happens to start off with
  2029.                   0x, interprets it as a hex string instead.)  The
  2030.                   following will handle decimal, octal, and hex in the
  2031.                   standard Perl or C notation:
  2032.  
  2033.                       $val = oct($val) if $val =~ /^0/;
  2034.  
  2035.                   If EXPR is omitted, uses $_.
  2036.  
  2037.           open FILEHANDLE,EXPR
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.      Page 31                                         (printed 6/30/95)
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2051.  
  2052.  
  2053.  
  2054.           open FILEHANDLE
  2055.                   Opens the file whose filename is given by EXPR, and
  2056.                   associates it with FILEHANDLE.  If FILEHANDLE is an
  2057.                   expression, its value is used as the name of the
  2058.                   real filehandle wanted.  If EXPR is omitted, the
  2059.                   scalar variable of the same name as the FILEHANDLE
  2060.                   contains the filename.  If the filename begins with
  2061.                   "<" or nothing, the file is opened for input.  If
  2062.                   the filename begins with ">", the file is opened for
  2063.                   output.  If the filename begins with ">>", the file
  2064.                   is opened for appending.  (You can put a '+' in
  2065.                   front of the '>' or '<' to indicate that you want
  2066.                   both read and write access to the file.)  If the
  2067.                   filename begins with "|", the filename is
  2068.                   interpreted as a command to which output is to be
  2069.                   piped, and if the filename ends with a "|", the
  2070.                   filename is interpreted as command which pipes input
  2071.                   to us.  (You may not have a command that pipes both
  2072.                   in and out.)  Opening '-' opens STDIN and opening
  2073.                   '>-' opens STDOUT.  Open returns non-zero upon
  2074.                   success, the undefined value otherwise.  If the open
  2075.                   involved a pipe, the return value happens to be the
  2076.                   pid of the subprocess.  Examples:
  2077.  
  2078.                       $ARTICLE = 100;
  2079.                       open ARTICLE or die "Can't find article $ARTICLE: $!\n";
  2080.                       while (<ARTICLE>) {...
  2081.  
  2082.                       open(LOG, '>>/usr/spool/news/twitlog'); # (log is reserved)
  2083.  
  2084.                       open(article, "caesar <$article |");    # decrypt article
  2085.  
  2086.                       open(extract, "|sort >/tmp/Tmp$$");     # $$ is our process id
  2087.  
  2088.                       # process argument list of files along with any includes
  2089.  
  2090.                       foreach $file (@ARGV) {
  2091.                           process($file, 'fh00');
  2092.                       }
  2093.  
  2094.                       sub process {
  2095.                           local($filename, $input) = @_;
  2096.                           $input++;               # this is a string increment
  2097.                           unless (open($input, $filename)) {
  2098.                               print STDERR "Can't open $filename: $!\n";
  2099.                               return;
  2100.                           }
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.  
  2107.  
  2108.  
  2109.      Page 32                                         (printed 6/30/95)
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2117.  
  2118.  
  2119.  
  2120.                           while (<$input>) {              # note use of indirection
  2121.                               if (/^#include "(.*)"/) {
  2122.                                   process($1, $input);
  2123.                                   next;
  2124.                               }
  2125.                               ...         # whatever
  2126.                           }
  2127.                       }
  2128.  
  2129.                   You may also, in the Bourne shell tradition, specify
  2130.                   an EXPR beginning with ">&", in which case the rest
  2131.                   of the string is interpreted as the name of a
  2132.                   filehandle (or file descriptor, if numeric) which is
  2133.                   to be duped and opened.  You may use & after >, >>,
  2134.                   <, +>, +>> and +<.  The mode you specify should
  2135.                   match the mode of the original filehandle.  Here is
  2136.                   a script that saves, redirects, and restores STDOUT
  2137.                   and STDERR:
  2138.  
  2139.                       #!/usr/bin/perl
  2140.                       open(SAVEOUT, ">&STDOUT");
  2141.                       open(SAVEERR, ">&STDERR");
  2142.  
  2143.                       open(STDOUT, ">foo.out") || die "Can't redirect stdout";
  2144.                       open(STDERR, ">&STDOUT") || die "Can't dup stdout";
  2145.  
  2146.                       select(STDERR); $| = 1;     # make unbuffered
  2147.                       select(STDOUT); $| = 1;     # make unbuffered
  2148.  
  2149.                       print STDOUT "stdout 1\n";  # this works for
  2150.                       print STDERR "stderr 1\n";  # subprocesses too
  2151.  
  2152.                       close(STDOUT);
  2153.                       close(STDERR);
  2154.  
  2155.                       open(STDOUT, ">&SAVEOUT");
  2156.                       open(STDERR, ">&SAVEERR");
  2157.  
  2158.                       print STDOUT "stdout 2\n";
  2159.                       print STDERR "stderr 2\n";
  2160.  
  2161.                   If you specify "<&=N", where N is a number, then
  2162.                   Perl will do an equivalent of C's _f_d_o_p_e_n() of that
  2163.                   file descriptor.  For example:
  2164.  
  2165.                       open(FILEHANDLE, "<&=$fd")
  2166.  
  2167.                   If you open a pipe on the command "-", i.e. either
  2168.                   "|-" or "-|", then there is an implicit fork done,
  2169.                   and the return value of open is the pid of the child
  2170.                   within the parent process, and 0 within the child
  2171.                   process.  (Use _d_e_f_i_n_e_d($pid) to determine whether
  2172.  
  2173.  
  2174.  
  2175.      Page 33                                         (printed 6/30/95)
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2183.  
  2184.  
  2185.  
  2186.                   the open was successful.) The filehandle behaves
  2187.                   normally for the parent, but i/o to that filehandle
  2188.                   is piped from/to the STDOUT/STDIN of the child
  2189.                   process.  In the child process the filehandle isn't
  2190.                   opened--i/o happens from/to the new STDOUT or STDIN.
  2191.                   Typically this is used like the normal piped open
  2192.                   when you want to exercise more control over just how
  2193.                   the pipe command gets executed, such as when you are
  2194.                   running setuid, and don't want to have to scan shell
  2195.                   commands for metacharacters.  The following pairs
  2196.                   are more or less equivalent:
  2197.  
  2198.                       open(FOO, "|tr '[a-z]' '[A-Z]'");
  2199.                       open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]';
  2200.  
  2201.                       open(FOO, "cat -n '$file'|");
  2202.                       open(FOO, "-|") || exec 'cat', '-n', $file;
  2203.  
  2204.                   Explicitly closing any piped filehandle causes the
  2205.                   parent process to wait for the child to finish, and
  2206.                   returns the status value in $?.  Note: on any
  2207.                   operation which may do a fork, unflushed buffers
  2208.                   remain unflushed in both processes, which means you
  2209.                   may need to set $| to avoid duplicate output.
  2210.  
  2211.                   The filename that is passed to open will have
  2212.                   leading and trailing whitespace deleted.  In order
  2213.                   to open a file with arbitrary weird characters in
  2214.                   it, it's necessary to protect any leading and
  2215.                   trailing whitespace thusly:
  2216.  
  2217.                           $file =~ s#^(\s)#./$1#;
  2218.                           open(FOO, "< $file\0");
  2219.  
  2220.  
  2221.           opendir DIRHANDLE,EXPR
  2222.                   Opens a directory named EXPR for processing by
  2223.                   _r_e_a_d_d_i_r(), _t_e_l_l_d_i_r(), _s_e_e_k_d_i_r(), _r_e_w_i_n_d_d_i_r() and
  2224.                   _c_l_o_s_e_d_i_r().  Returns TRUE if successful.  DIRHANDLEs
  2225.                   have their own namespace separate from FILEHANDLEs.
  2226.  
  2227.           ord EXPR
  2228.                   Returns the numeric ascii value of the first
  2229.                   character of EXPR.  If EXPR is omitted, uses $_.
  2230.  
  2231.           pack TEMPLATE,LIST
  2232.                   Takes an array or list of values and packs it into a
  2233.                   binary structure, returning the string containing
  2234.                   the structure.  The TEMPLATE is a sequence of
  2235.                   characters that give the order and type of values,
  2236.                   as follows:
  2237.  
  2238.  
  2239.  
  2240.  
  2241.      Page 34                                         (printed 6/30/95)
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2249.  
  2250.  
  2251.  
  2252.                       A   An ascii string, will be space padded.
  2253.                       a   An ascii string, will be null padded.
  2254.                       b   A bit string (ascending bit order, like vec()).
  2255.                       B   A bit string (descending bit order).
  2256.                       h   A hex string (low nybble first).
  2257.                       H   A hex string (high nybble first).
  2258.  
  2259.                       c   A signed char value.
  2260.                       C   An unsigned char value.
  2261.                       s   A signed short value.
  2262.                       S   An unsigned short value.
  2263.                       i   A signed integer value.
  2264.                       I   An unsigned integer value.
  2265.                       l   A signed long value.
  2266.                       L   An unsigned long value.
  2267.  
  2268.                       n   A short in "network" order.
  2269.                       N   A long in "network" order.
  2270.                       v   A short in "VAX" (little-endian) order.
  2271.                       V   A long in "VAX" (little-endian) order.
  2272.  
  2273.                       f   A single-precision float in the native format.
  2274.                       d   A double-precision float in the native format.
  2275.  
  2276.                       p   A pointer to a null-terminated string.
  2277.                       P   A pointer to a structure (fixed-length string).
  2278.  
  2279.                       u   A uuencoded string.
  2280.  
  2281.                       x   A null byte.
  2282.                       X   Back up a byte.
  2283.                       @   Null fill to absolute position.
  2284.  
  2285.                   Each letter may optionally be followed by a number
  2286.                   which gives a repeat count.  With all types except
  2287.                   "a", "A", "b", "B", "h" and "H", and "P" the pack
  2288.                   function will gobble up that many values from the
  2289.                   LIST.  A * for the repeat count means to use however
  2290.                   many items are left.  The "a" and "A" types gobble
  2291.                   just one value, but pack it as a string of length
  2292.                   count, padding with nulls or spaces as necessary.
  2293.                   (When unpacking, "A" strips trailing spaces and
  2294.                   nulls, but "a" does not.)  Likewise, the "b" and "B"
  2295.                   fields pack a string that many bits long.  The "h"
  2296.                   and "H" fields pack a string that many nybbles long.
  2297.                   The "P" packs a pointer to a structure of the size
  2298.                   indicated by the length.  Real numbers (floats and
  2299.                   doubles) are in the native machine format only; due
  2300.                   to the multiplicity of floating formats around, and
  2301.                   the lack of a standard "network" representation, no
  2302.                   facility for interchange has been made.  This means
  2303.                   that packed floating point data written on one
  2304.  
  2305.  
  2306.  
  2307.      Page 35                                         (printed 6/30/95)
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2315.  
  2316.  
  2317.  
  2318.                   machine may not be readable on another - even if
  2319.                   both use IEEE floating point arithmetic (as the
  2320.                   endian-ness of the memory representation is not part
  2321.                   of the IEEE spec).  Note that Perl uses doubles
  2322.                   internally for all numeric calculation, and
  2323.                   converting from double into float and thence back to
  2324.                   double again will lose precision (i.e.  unpack("f",
  2325.                   pack("f", $foo)) will not in general equal $foo).
  2326.  
  2327.                   Examples:
  2328.  
  2329.                       $foo = pack("cccc",65,66,67,68);
  2330.                       # foo eq "ABCD"
  2331.                       $foo = pack("c4",65,66,67,68);
  2332.                       # same thing
  2333.  
  2334.                       $foo = pack("ccxxcc",65,66,67,68);
  2335.                       # foo eq "AB\0\0CD"
  2336.  
  2337.                       $foo = pack("s2",1,2);
  2338.                       # "\1\0\2\0" on little-endian
  2339.                       # "\0\1\0\2" on big-endian
  2340.  
  2341.                       $foo = pack("a4","abcd","x","y","z");
  2342.                       # "abcd"
  2343.  
  2344.                       $foo = pack("aaaa","abcd","x","y","z");
  2345.                       # "axyz"
  2346.  
  2347.                       $foo = pack("a14","abcdefg");
  2348.                       # "abcdefg\0\0\0\0\0\0\0"
  2349.  
  2350.                       $foo = pack("i9pl", gmtime);
  2351.                       # a real struct tm (on my system anyway)
  2352.  
  2353.                       sub bintodec {
  2354.                           unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
  2355.                       }
  2356.  
  2357.                   The same template may generally also be used in the
  2358.                   unpack function.
  2359.  
  2360.           pipe READHANDLE,WRITEHANDLE
  2361.                   Opens a pair of connected pipes like the
  2362.                   corresponding system call.  Note that if you set up
  2363.                   a loop of piped processes, deadlock can occur unless
  2364.                   you are very careful.  In addition, note that Perl's
  2365.                   pipes use stdio buffering, so you may need to set $|
  2366.                   to flush your WRITEHANDLE after each command,
  2367.                   depending on the application.
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.      Page 36                                         (printed 6/30/95)
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2381.  
  2382.  
  2383.  
  2384.           pop ARRAY
  2385.                   Pops and returns the last value of the array,
  2386.                   shortening the array by 1.  Has a similar effect to
  2387.  
  2388.                       $tmp = $ARRAY[$#ARRAY--];
  2389.  
  2390.                   If there are no elements in the array, returns the
  2391.                   undefined value.
  2392.  
  2393.           pos SCALAR
  2394.                   Returns the offset of where the last m//g search
  2395.                   left off for the variable in question.  May be
  2396.                   modified to change that offset.
  2397.  
  2398.           print FILEHANDLE LIST
  2399.  
  2400.           print LIST
  2401.  
  2402.           print   Prints a string or a comma-separated list of
  2403.                   strings.  Returns non-zero if successful.
  2404.                   FILEHANDLE may be a scalar variable name, in which
  2405.                   case the variable contains the name of the
  2406.                   filehandle, thus introducing one level of
  2407.                   indirection.  (NOTE: If FILEHANDLE is a variable and
  2408.                   the next token is a term, it may be misinterpreted
  2409.                   as an operator unless you interpose a + or put
  2410.                   parens around the arguments.)  If FILEHANDLE is
  2411.                   omitted, prints by default to standard output (or to
  2412.                   the last selected output channel--see _s_e_l_e_c_t()).  If
  2413.                   LIST is also omitted, prints $_ to STDOUT.  To set
  2414.                   the default output channel to something other than
  2415.                   STDOUT use the select operation.  Note that, because
  2416.                   print takes a LIST, anything in the LIST is
  2417.                   evaluated in a list context, and any subroutine that
  2418.                   you call will have one or more of its expressions
  2419.                   evaluated in a list context.  Also be careful not to
  2420.                   follow the print keyword with a left parenthesis
  2421.                   unless you want the corresponding right parenthesis
  2422.                   to terminate the arguments to the print--interpose a
  2423.                   + or put parens around all the arguments.
  2424.  
  2425.           printf FILEHANDLE LIST
  2426.  
  2427.           printf LIST
  2428.                   Equivalent to a "print FILEHANDLE _s_p_r_i_n_t_f(LIST)".
  2429.                   The first argument of the list will be interpreted
  2430.                   as the printf format.
  2431.  
  2432.           push ARRAY,LIST
  2433.                   Treats ARRAY as a stack, and pushes the values of
  2434.                   LIST onto the end of ARRAY.  The length of ARRAY
  2435.                   increases by the length of LIST.  Has the same
  2436.  
  2437.  
  2438.  
  2439.      Page 37                                         (printed 6/30/95)
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2447.  
  2448.  
  2449.  
  2450.                   effect as
  2451.  
  2452.                       for $value (LIST) {
  2453.                           $ARRAY[++$#ARRAY] = $value;
  2454.                       }
  2455.  
  2456.                   but is more efficient.  Returns the new number of
  2457.                   elements in the array.
  2458.  
  2459.           q/STRING/
  2460.  
  2461.           qq/STRING/
  2462.  
  2463.           qx/STRING/
  2464.  
  2465.           qw/STRING/
  2466.                   Generalized quotes.  See the _p_e_r_l_o_p manpage.
  2467.  
  2468.           quotemeta EXPR
  2469.                   Returns the value of EXPR with with all regular
  2470.                   expression metacharacters backslashed.  This is the
  2471.                   internal function implementing the \Q escape in
  2472.                   double-quoted strings.
  2473.  
  2474.           rand EXPR
  2475.  
  2476.           rand    Returns a random fractional number between 0 and the
  2477.                   value of EXPR.  (EXPR should be positive.)  If EXPR
  2478.                   is omitted, returns a value between 0 and 1.  This
  2479.                   function produces repeatable sequences unless
  2480.                   _s_r_a_n_d() is invoked.  See also _s_r_a_n_d().
  2481.  
  2482.                   (Note: if your rand function consistently returns
  2483.                   numbers that are too large or too small, then your
  2484.                   version of Perl was probably compiled with the wrong
  2485.                   number of RANDBITS.  As a workaround, you can
  2486.                   usually multiply EXPR by the correct power of 2 to
  2487.                   get the range you want.  This will make your script
  2488.                   unportable, however.  It's better to recompile if
  2489.                   you can.)
  2490.  
  2491.           read FILEHANDLE,SCALAR,LENGTH,OFFSET
  2492.  
  2493.           read FILEHANDLE,SCALAR,LENGTH
  2494.                   Attempts to read LENGTH bytes of data into variable
  2495.                   SCALAR from the specified FILEHANDLE.  Returns the
  2496.                   number of bytes actually read, or undef if there was
  2497.                   an error.  SCALAR will be grown or shrunk to the
  2498.                   length actually read.  An OFFSET may be specified to
  2499.                   place the read data at some other place than the
  2500.                   beginning of the string.  This call is actually
  2501.                   implemented in terms of stdio's fread call.  To get
  2502.  
  2503.  
  2504.  
  2505.      Page 38                                         (printed 6/30/95)
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2513.  
  2514.  
  2515.  
  2516.                   a true read system call, see _s_y_s_r_e_a_d().
  2517.  
  2518.           readdir DIRHANDLE
  2519.                   Returns the next directory entry for a directory
  2520.                   opened by _o_p_e_n_d_i_r().  If used in a list context,
  2521.                   returns all the rest of the entries in the
  2522.                   directory.  If there are no more entries, returns an
  2523.                   undefined value in a scalar context or a null list
  2524.                   in a list context.
  2525.  
  2526.           readlink EXPR
  2527.                   Returns the value of a symbolic link, if symbolic
  2528.                   links are implemented.  If not, gives a fatal error.
  2529.                   If there is some system error, returns the undefined
  2530.                   value and sets $! (errno).  If EXPR is omitted, uses
  2531.                   $_.
  2532.  
  2533.           recv SOCKET,SCALAR,LEN,FLAGS
  2534.                   Receives a message on a socket.  Attempts to receive
  2535.                   LENGTH bytes of data into variable SCALAR from the
  2536.                   specified SOCKET filehandle.  Actually does a C
  2537.                   _r_e_c_v_f_r_o_m(), so that it can returns the address of
  2538.                   the sender.  Returns the undefined value if there's
  2539.                   an error.  SCALAR will be grown or shrunk to the
  2540.                   length actually read.  Takes the same flags as the
  2541.                   system call of the same name.
  2542.  
  2543.           redo LABEL
  2544.  
  2545.           redo    The redo command restarts the loop block without
  2546.                   evaluating the conditional again.  The continue
  2547.                   block, if any, is not executed.  If the LABEL is
  2548.                   omitted, the command refers to the innermost
  2549.                   enclosing loop.  This command is normally used by
  2550.                   programs that want to lie to themselves about what
  2551.                   was just input:
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.      Page 39                                         (printed 6/30/95)
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2579.  
  2580.  
  2581.  
  2582.                       # a simpleminded Pascal comment stripper
  2583.                       # (warning: assumes no { or } in strings)
  2584.                       line: while (<STDIN>) {
  2585.                           while (s|({.*}.*){.*}|$1 |) {}
  2586.                           s|{.*}| |;
  2587.                           if (s|{.*| |) {
  2588.                               $front = $_;
  2589.                               while (<STDIN>) {
  2590.                                   if (/}/) {      # end of comment?
  2591.                                       s|^|$front{|;
  2592.                                       redo line;
  2593.                                   }
  2594.                               }
  2595.                           }
  2596.                           print;
  2597.                       }
  2598.  
  2599.  
  2600.           ref EXPR
  2601.                   Returns a TRUE value if EXPR is a reference, FALSE
  2602.                   otherwise.  The value returned depends on the type
  2603.                   of thing the reference is a reference to.  Builtin
  2604.                   types include:
  2605.  
  2606.                       REF
  2607.                       SCALAR
  2608.                       ARRAY
  2609.                       HASH
  2610.                       CODE
  2611.                       GLOB
  2612.  
  2613.                   If the referenced object has been blessed into a
  2614.                   package, then that package name is returned instead.
  2615.                   You can think of _r_e_f() as a _t_y_p_e_o_f() operator.
  2616.  
  2617.                       if (ref($r) eq "HASH") {
  2618.                           print "r is a reference to an associative array.\n";
  2619.                       }
  2620.                       if (!ref ($r) {
  2621.                           print "r is not a reference at all.\n";
  2622.                       }
  2623.  
  2624.                   See also the _p_e_r_l_r_e_f manpage.
  2625.  
  2626.           rename OLDNAME,NEWNAME
  2627.                   Changes the name of a file.  Returns 1 for success,
  2628.                   0 otherwise.  Will not work across filesystem
  2629.                   boundaries.
  2630.  
  2631.           require EXPR
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.      Page 40                                         (printed 6/30/95)
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2645.  
  2646.  
  2647.  
  2648.           require Demands some semantics specified by EXPR, or by $_
  2649.                   if EXPR is not supplied.  If EXPR is numeric,
  2650.                   demands that the current version of Perl ($] or
  2651.                   $PERL_VERSION) be equal or greater than EXPR.
  2652.  
  2653.                   Otherwise, demands that a library file be included
  2654.                   if it hasn't already been included.  The file is
  2655.                   included via the do-FILE mechanism, which is
  2656.                   essentially just a variety of _e_v_a_l().  Has semantics
  2657.                   similar to the following subroutine:
  2658.  
  2659.                       sub require {
  2660.                           local($filename) = @_;
  2661.                           return 1 if $INC{$filename};
  2662.                           local($realfilename,$result);
  2663.                           ITER: {
  2664.                               foreach $prefix (@INC) {
  2665.                                   $realfilename = "$prefix/$filename";
  2666.                                   if (-f $realfilename) {
  2667.                                       $result = do $realfilename;
  2668.                                       last ITER;
  2669.                                   }
  2670.                               }
  2671.                               die "Can't find $filename in \@INC";
  2672.                           }
  2673.                           die $@ if $@;
  2674.                           die "$filename did not return true value" unless $result;
  2675.                           $INC{$filename} = $realfilename;
  2676.                           $result;
  2677.                       }
  2678.  
  2679.                   Note that the file will not be included twice under
  2680.                   the same specified name.  The file must return TRUE
  2681.                   as the last statement to indicate successful
  2682.                   execution of any initialization code, so it's
  2683.                   customary to end such a file with "1;" unless you're
  2684.                   sure it'll return TRUE otherwise.  But it's better
  2685.                   just to put the "1;", in case you add more
  2686.                   statements.
  2687.  
  2688.                   If EXPR is a bare word, the require assumes a "._p_m"
  2689.                   extension for you, to make it easy to load standard
  2690.                   modules.  This form of loading of modules does not
  2691.                   risk altering your namespace.
  2692.  
  2693.                   For a yet more powerful import facility, see the the
  2694.                   use() entry elsewhere in this documentbelow, and
  2695.                   also the _p_e_r_l_m_o_d manpage.
  2696.  
  2697.           reset EXPR
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.      Page 41                                         (printed 6/30/95)
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2711.  
  2712.  
  2713.  
  2714.           reset   Generally used in a continue block at the end of a
  2715.                   loop to clear variables and reset ?? searches so
  2716.                   that they work again.  The expression is interpreted
  2717.                   as a list of single characters (hyphens allowed for
  2718.                   ranges).  All variables and arrays beginning with
  2719.                   one of those letters are reset to their pristine
  2720.                   state.  If the expression is omitted, one-match
  2721.                   searches (?pattern?) are reset to match again.  Only
  2722.                   resets variables or searches in the current package.
  2723.                   Always returns 1.  Examples:
  2724.  
  2725.                       reset 'X';          # reset all X variables
  2726.                       reset 'a-z';        # reset lower case variables
  2727.                       reset;              # just reset ?? searches
  2728.  
  2729.                   Resetting "A-Z" is not recommended since you'll wipe
  2730.                   out your ARGV and ENV arrays.  Only resets package
  2731.                   variables--lexical variables are unaffected, but
  2732.                   they clean themselves up on scope exit anyway, so
  2733.                   anymore you probably want to use them instead.  See
  2734.                   the my entry elsewhere in this document.
  2735.  
  2736.           return LIST
  2737.                   Returns from a subroutine or eval with the value
  2738.                   specified.  (Note that in the absence of a return a
  2739.                   subroutine or eval will automatically return the
  2740.                   value of the last expression evaluated.)
  2741.  
  2742.           reverse LIST
  2743.                   In a list context, returns a list value consisting
  2744.                   of the elements of LIST in the opposite order.  In a
  2745.                   scalar context, returns a string value consisting of
  2746.                   the bytes of the first element of LIST in the
  2747.                   opposite order.
  2748.  
  2749.           rewinddir DIRHANDLE
  2750.                   Sets the current position to the beginning of the
  2751.                   directory for the _r_e_a_d_d_i_r() routine on DIRHANDLE.
  2752.  
  2753.           rindex STR,SUBSTR,POSITION
  2754.  
  2755.           rindex STR,SUBSTR
  2756.                   Works just like index except that it returns the
  2757.                   position of the LAST occurrence of SUBSTR in STR.
  2758.                   If POSITION is specified, returns the last
  2759.                   occurrence at or before that position.
  2760.  
  2761.           rmdir FILENAME
  2762.                   Deletes the directory specified by FILENAME if it is
  2763.                   empty.  If it succeeds it returns 1, otherwise it
  2764.                   returns 0 and sets $! (errno).  If FILENAME is
  2765.                   omitted, uses $_.
  2766.  
  2767.  
  2768.  
  2769.      Page 42                                         (printed 6/30/95)
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2777.  
  2778.  
  2779.  
  2780.           s///    The substitution operator.  See the _p_e_r_l_o_p manpage.
  2781.  
  2782.           scalar EXPR
  2783.                   Forces EXPR to be interpreted in a scalar context
  2784.                   and returns the value of EXPR.
  2785.  
  2786.           seek FILEHANDLE,POSITION,WHENCE
  2787.                   Randomly positions the file pointer for FILEHANDLE,
  2788.                   just like the _f_s_e_e_k() call of stdio.  FILEHANDLE may
  2789.                   be an expression whose value gives the name of the
  2790.                   filehandle.  The values for WHENCE are 0 to set the
  2791.                   file pointer to POSITION, 1 to set the it to current
  2792.                   plus POSITION, and 2 to set it to EOF plus offset.
  2793.                   You may use the values SEEK_SET, SEEK_CUR, and
  2794.                   SEEK_END for this is usin the POSIX module.  Returns
  2795.                   1 upon success, 0 otherwise.
  2796.  
  2797.           seekdir DIRHANDLE,POS
  2798.                   Sets the current position for the _r_e_a_d_d_i_r() routine
  2799.                   on DIRHANDLE.  POS must be a value returned by
  2800.                   _t_e_l_l_d_i_r().  Has the same caveats about possible
  2801.                   directory compaction as the corresponding system
  2802.                   library routine.
  2803.  
  2804.           select FILEHANDLE
  2805.  
  2806.           select  Returns the currently selected filehandle.  Sets the
  2807.                   current default filehandle for output, if FILEHANDLE
  2808.                   is supplied.  This has two effects: first, a write
  2809.                   or a print without a filehandle will default to this
  2810.                   FILEHANDLE.  Second, references to variables related
  2811.                   to output will refer to this output channel.  For
  2812.                   example, if you have to set the top of form format
  2813.                   for more than one output channel, you might do the
  2814.                   following:
  2815.  
  2816.                       select(REPORT1);
  2817.                       $^ = 'report1_top';
  2818.                       select(REPORT2);
  2819.                       $^ = 'report2_top';
  2820.  
  2821.                   FILEHANDLE may be an expression whose value gives
  2822.                   the name of the actual filehandle.  Thus:
  2823.  
  2824.                       $oldfh = select(STDERR); $| = 1; select($oldfh);
  2825.  
  2826.                   With Perl 5, filehandles are objects with methods,
  2827.                   and the last example is preferably written
  2828.  
  2829.                       use FileHandle;
  2830.                       STDERR->autoflush(1);
  2831.  
  2832.  
  2833.  
  2834.  
  2835.      Page 43                                         (printed 6/30/95)
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2843.  
  2844.  
  2845.  
  2846.           select RBITS,WBITS,EBITS,TIMEOUT
  2847.                   This calls the select _s_y_s_t_e_m(2) call with the
  2848.                   bitmasks specified, which can be constructed using
  2849.                   _f_i_l_e_n_o() and _v_e_c(), along these lines:
  2850.  
  2851.                       $rin = $win = $ein = '';
  2852.                       vec($rin,fileno(STDIN),1) = 1;
  2853.                       vec($win,fileno(STDOUT),1) = 1;
  2854.                       $ein = $rin | $win;
  2855.  
  2856.                   If you want to select on many filehandles you might
  2857.                   wish to write a subroutine:
  2858.  
  2859.                       sub fhbits {
  2860.                           local(@fhlist) = split(' ',$_[0]);
  2861.                           local($bits);
  2862.                           for (@fhlist) {
  2863.                               vec($bits,fileno($_),1) = 1;
  2864.                           }
  2865.                           $bits;
  2866.                       }
  2867.                       $rin = &fhbits('STDIN TTY SOCK');
  2868.  
  2869.                   The usual idiom is:
  2870.  
  2871.                       ($nfound,$timeleft) =
  2872.                         select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
  2873.  
  2874.                   or to block until something becomes ready:
  2875.  
  2876.                       $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
  2877.  
  2878.                   Any of the bitmasks can also be undef.  The timeout,
  2879.                   if specified, is in seconds, which may be
  2880.                   fractional.  Note: not all implementations are
  2881.                   capable of returning the $timeleft.  If not, they
  2882.                   always return $timeleft equal to the supplied
  2883.                   $timeout.
  2884.  
  2885.                   You can effect a 250 microsecond sleep this way:
  2886.  
  2887.                       select(undef, undef, undef, 0.25);
  2888.  
  2889.  
  2890.           semctl ID,SEMNUM,CMD,ARG
  2891.                   Calls the System V IPC function semctl.  If CMD is
  2892.                   &IPC_STAT or &GETALL, then ARG must be a variable
  2893.                   which will hold the returned semid_ds structure or
  2894.                   semaphore value array.  Returns like ioctl: the
  2895.                   undefined value for error, "0 but true" for zero, or
  2896.                   the actual return value otherwise.
  2897.  
  2898.  
  2899.  
  2900.  
  2901.      Page 44                                         (printed 6/30/95)
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2909.  
  2910.  
  2911.  
  2912.           semget KEY,NSEMS,FLAGS
  2913.                   Calls the System V IPC function semget.  Returns the
  2914.                   semaphore id, or the undefined value if there is an
  2915.                   error.
  2916.  
  2917.           semop KEY,OPSTRING
  2918.                   Calls the System V IPC function semop to perform
  2919.                   semaphore operations such as signaling and waiting.
  2920.                   OPSTRING must be a packed array of semop structures.
  2921.                   Each semop structure can be generated with
  2922.                   pack("sss", $semnum, $semop, $semflag).  The number
  2923.                   of semaphore operations is implied by the length of
  2924.                   OPSTRING.  Returns TRUE if successful, or FALSE if
  2925.                   there is an error.  As an example, the following
  2926.                   code waits on semaphore $semnum of semaphore id
  2927.                   $semid:
  2928.  
  2929.                       $semop = pack("sss", $semnum, -1, 0);
  2930.                       die "Semaphore trouble: $!\n" unless semop($semid, $semop);
  2931.  
  2932.                   To signal the semaphore, replace "-1" with "1".
  2933.  
  2934.           send SOCKET,MSG,FLAGS,TO
  2935.  
  2936.           send SOCKET,MSG,FLAGS
  2937.                   Sends a message on a socket.  Takes the same flags
  2938.                   as the system call of the same name.  On unconnected
  2939.                   sockets you must specify a destination to send TO,
  2940.                   in which case it does a C _s_e_n_d_t_o().  Returns the
  2941.                   number of characters sent, or the undefined value if
  2942.                   there is an error.
  2943.  
  2944.           setpgrp PID,PGRP
  2945.                   Sets the current process group for the specified
  2946.                   PID, 0 for the current process.  Will produce a
  2947.                   fatal error if used on a machine that doesn't
  2948.                   implement _s_e_t_p_g_r_p(2).
  2949.  
  2950.           setpriority WHICH,WHO,PRIORITY
  2951.                   Sets the current priority for a process, a process
  2952.                   group, or a user.  (See _L_s_e_t_p_r_i_o_r_i_t_y(2)>.)  Will
  2953.                   produce a fatal error if used on a machine that
  2954.                   doesn't implement _s_e_t_p_r_i_o_r_i_t_y(2).
  2955.  
  2956.           setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
  2957.                   Sets the socket option requested.  Returns undefined
  2958.                   if there is an error.  OPTVAL may be specified as
  2959.                   undef if you don't want to pass an argument.
  2960.  
  2961.           shift ARRAY
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.      Page 45                                         (printed 6/30/95)
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  2975.  
  2976.  
  2977.  
  2978.           shift   Shifts the first value of the array off and returns
  2979.                   it, shortening the array by 1 and moving everything
  2980.                   down.  If there are no elements in the array,
  2981.                   returns the undefined value.  If ARRAY is omitted,
  2982.                   shifts the @ARGV array in the main program, and the
  2983.                   @_ array in subroutines.  (This is determined
  2984.                   lexically.)  See also _u_n_s_h_i_f_t(), _p_u_s_h(), and _p_o_p().
  2985.                   _S_h_i_f_t() and _u_n_s_h_i_f_t() do the same thing to the left
  2986.                   end of an array that _p_u_s_h() and _p_o_p() do to the
  2987.                   right end.
  2988.  
  2989.           shmctl ID,CMD,ARG
  2990.                   Calls the System V IPC function shmctl.  If CMD is
  2991.                   &IPC_STAT, then ARG must be a variable which will
  2992.                   hold the returned shmid_ds structure.  Returns like
  2993.                   ioctl: the undefined value for error, "0 but true"
  2994.                   for zero, or the actual return value otherwise.
  2995.  
  2996.           shmget KEY,SIZE,FLAGS
  2997.                   Calls the System V IPC function shmget.  Returns the
  2998.                   shared memory segment id, or the undefined value if
  2999.                   there is an error.
  3000.  
  3001.           shmread ID,VAR,POS,SIZE
  3002.  
  3003.           shmwrite ID,STRING,POS,SIZE
  3004.                   Reads or writes the System V shared memory segment
  3005.                   ID starting at position POS for size SIZE by
  3006.                   attaching to it, copying in/out, and detaching from
  3007.                   it.  When reading, VAR must be a variable which will
  3008.                   hold the data read.  When writing, if STRING is too
  3009.                   long, only SIZE bytes are used; if STRING is too
  3010.                   short, nulls are written to fill out SIZE bytes.
  3011.                   Return TRUE if successful, or FALSE if there is an
  3012.                   error.
  3013.  
  3014.           shutdown SOCKET,HOW
  3015.                   Shuts down a socket connection in the manner
  3016.                   indicated by HOW, which has the same interpretation
  3017.                   as in the system call of the same name.
  3018.  
  3019.           sin EXPR
  3020.                   Returns the sine of EXPR (expressed in radians).  If
  3021.                   EXPR is omitted, returns sine of $_.
  3022.  
  3023.           sleep EXPR
  3024.  
  3025.           sleep   Causes the script to sleep for EXPR seconds, or
  3026.                   forever if no EXPR.  May be interrupted by sending
  3027.                   the process a SIGALRM.  Returns the number of
  3028.                   seconds actually slept.  You probably cannot mix
  3029.                   _a_l_a_r_m() and _s_l_e_e_p() calls, since _s_l_e_e_p() is often
  3030.  
  3031.  
  3032.  
  3033.      Page 46                                         (printed 6/30/95)
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3041.  
  3042.  
  3043.  
  3044.                   implemented using _a_l_a_r_m().
  3045.  
  3046.                   On some older systems, it may sleep up to a full
  3047.                   second less than what you requested, depending on
  3048.                   how it counts seconds.  Most modern systems always
  3049.                   sleep the full amount.
  3050.  
  3051.           socket SOCKET,DOMAIN,TYPE,PROTOCOL
  3052.                   Opens a socket of the specified kind and attaches it
  3053.                   to filehandle SOCKET.  DOMAIN, TYPE and PROTOCOL are
  3054.                   specified the same as for the system call of the
  3055.                   same name.  You should "use Socket;" first to get
  3056.                   the proper definitions imported.  See the example in
  3057.                   the _p_e_r_l_i_p_c manpage.
  3058.  
  3059.           socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
  3060.                   Creates an unnamed pair of sockets in the specified
  3061.                   domain, of the specified type.  DOMAIN, TYPE and
  3062.                   PROTOCOL are specified the same as for the system
  3063.                   call of the same name.  If unimplemented, yields a
  3064.                   fatal error.  Returns TRUE if successful.
  3065.  
  3066.           sort SUBNAME LIST
  3067.  
  3068.           sort BLOCK LIST
  3069.  
  3070.           sort LIST
  3071.                   Sorts the LIST and returns the sorted list value.
  3072.                   Nonexistent values of arrays are stripped out.  If
  3073.                   SUBNAME or BLOCK is omitted, sorts in standard
  3074.                   string comparison order.  If SUBNAME is specified,
  3075.                   it gives the name of a subroutine that returns an
  3076.                   integer less than, equal to, or greater than 0,
  3077.                   depending on how the elements of the array are to be
  3078.                   ordered.  (The <=> and cmp operators are extremely
  3079.                   useful in such routines.)  SUBNAME may be a scalar
  3080.                   variable name, in which case the value provides the
  3081.                   name of the subroutine to use.  In place of a
  3082.                   SUBNAME, you can provide a BLOCK as an anonymous,
  3083.                   in-line sort subroutine.
  3084.  
  3085.                   In the interests of efficiency the normal calling
  3086.                   code for subroutines is bypassed, with the following
  3087.                   effects: the subroutine may not be a recursive
  3088.                   subroutine, and the two elements to be compared are
  3089.                   passed into the subroutine not via @_ but as $a and
  3090.                   $b (see example below).  They are passed by
  3091.                   reference, so don't modify $a and $b.
  3092.  
  3093.                   Examples:
  3094.  
  3095.  
  3096.  
  3097.  
  3098.  
  3099.      Page 47                                         (printed 6/30/95)
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3107.  
  3108.  
  3109.  
  3110.                       # sort lexically
  3111.                       @articles = sort @files;
  3112.  
  3113.                       # same thing, but with explicit sort routine
  3114.                       @articles = sort {$a cmp $b} @files;
  3115.  
  3116.                       # same thing in reversed order
  3117.                       @articles = sort {$b cmp $a} @files;
  3118.  
  3119.                       # sort numerically ascending
  3120.                       @articles = sort {$a <=> $b} @files;
  3121.  
  3122.                       # sort numerically descending
  3123.                       @articles = sort {$b <=> $a} @files;
  3124.  
  3125.                       # sort using explicit subroutine name
  3126.                       sub byage {
  3127.                           $age{$a} <=> $age{$b};  # presuming integers
  3128.                       }
  3129.                       @sortedclass = sort byage @class;
  3130.  
  3131.                       sub backwards { $b cmp $a; }
  3132.                       @harry = ('dog','cat','x','Cain','Abel');
  3133.                       @george = ('gone','chased','yz','Punished','Axed');
  3134.                       print sort @harry;
  3135.                               # prints AbelCaincatdogx
  3136.                       print sort backwards @harry;
  3137.                               # prints xdogcatCainAbel
  3138.                       print sort @george, 'to', @harry;
  3139.                               # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
  3140.  
  3141.  
  3142.           splice ARRAY,OFFSET,LENGTH,LIST
  3143.  
  3144.           splice ARRAY,OFFSET,LENGTH
  3145.  
  3146.           splice ARRAY,OFFSET
  3147.                   Removes the elements designated by OFFSET and LENGTH
  3148.                   from an array, and replaces them with the elements
  3149.                   of LIST, if any.  Returns the elements removed from
  3150.                   the array.  The array grows or shrinks as necessary.
  3151.                   If LENGTH is omitted, removes everything from OFFSET
  3152.                   onward.  The following equivalencies hold (assuming
  3153.                   $[ == 0):
  3154.  
  3155.                       push(@a,$x,$y)      splice(@a,$#a+1,0,$x,$y)
  3156.                       pop(@a)             splice(@a,-1)
  3157.                       shift(@a)           splice(@a,0,1)
  3158.                       unshift(@a,$x,$y)   splice(@a,0,0,$x,$y)
  3159.                       $a[$x] = $y         splice(@a,$x,1,$y);
  3160.  
  3161.                   Example, assuming array lengths are passed before
  3162.  
  3163.  
  3164.  
  3165.      Page 48                                         (printed 6/30/95)
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3173.  
  3174.  
  3175.  
  3176.                   arrays:
  3177.  
  3178.                       sub aeq {   # compare two list values
  3179.                           local(@a) = splice(@_,0,shift);
  3180.                           local(@b) = splice(@_,0,shift);
  3181.                           return 0 unless @a == @b;       # same len?
  3182.                           while (@a) {
  3183.                               return 0 if pop(@a) ne pop(@b);
  3184.                           }
  3185.                           return 1;
  3186.                       }
  3187.                       if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
  3188.  
  3189.  
  3190.           split /PATTERN/,EXPR,LIMIT
  3191.  
  3192.           split /PATTERN/,EXPR
  3193.  
  3194.           split /PATTERN/
  3195.  
  3196.           split   Splits a string into an array of strings, and
  3197.                   returns it.
  3198.  
  3199.                   If not in a list context, returns the number of
  3200.                   fields found and splits into the @_ array.  (In a
  3201.                   list context, you can force the split into @_ by
  3202.                   using ?? as the pattern delimiters, but it still
  3203.                   returns the array value.)  The use of implicit split
  3204.                   to @_ is deprecated, however.
  3205.  
  3206.                   If EXPR is omitted, splits the $_ string.  If
  3207.                   PATTERN is also omitted, splits on whitespace (/[
  3208.                   \t\n]+/).  Anything matching PATTERN is taken to be
  3209.                   a delimiter separating the fields.  (Note that the
  3210.                   delimiter may be longer than one character.)  If
  3211.                   LIMIT is specified and is not negative, splits into
  3212.                   no more than that many fields (though it may split
  3213.                   into fewer).  If LIMIT is unspecified, trailing null
  3214.                   fields are stripped (which potential users of _p_o_p()
  3215.                   would do well to remember).  If LIMIT is negative,
  3216.                   it is treated as if an arbitrarily large LIMIT had
  3217.                   been specified.
  3218.  
  3219.                   A pattern matching the null string (not to be
  3220.                   confused with a null pattern C<//., which is just
  3221.                   one member of the set of patterns matching a null
  3222.                   string) will split the value of EXPR into separate
  3223.                   characters at each point it matches that way.  For
  3224.                   example:
  3225.  
  3226.                       print join(':', split(/ */, 'hi there'));
  3227.  
  3228.  
  3229.  
  3230.  
  3231.      Page 49                                         (printed 6/30/95)
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3239.  
  3240.  
  3241.  
  3242.                   produces the output 'h:i:t:h:e:r:e'.
  3243.  
  3244.                   The LIMIT parameter can be used to partially split a
  3245.                   line
  3246.  
  3247.                       ($login, $passwd, $remainder) = split(/:/, $_, 3);
  3248.  
  3249.                   When assigning to a list, if LIMIT is omitted, Perl
  3250.                   supplies a LIMIT one larger than the number of
  3251.                   variables in the list, to avoid unnecessary work.
  3252.                   For the list above LIMIT would have been 4 by
  3253.                   default.  In time critical applications it behooves
  3254.                   you not to split into more fields than you really
  3255.                   need.
  3256.  
  3257.                   If the PATTERN contains parentheses, additional
  3258.                   array elements are created from each matching
  3259.                   substring in the delimiter.
  3260.  
  3261.                       split(/([,-])/, "1-10,20");
  3262.  
  3263.                   produces the list value
  3264.  
  3265.                       (1, '-', 10, ',', 20)
  3266.  
  3267.                   The pattern /PATTERN/ may be replaced with an
  3268.                   expression to specify patterns that vary at runtime.
  3269.                   (To do runtime compilation only once, use
  3270.                   /$variable/o.)  As a special case, specifying a
  3271.                   space (' ') will split on white space just as split
  3272.                   with no arguments does, but leading white space does
  3273.                   _N_O_T produce a null first field.  Thus, split(' ')
  3274.                   can be used to emulate aaaawwwwkkkk's default behavior,
  3275.                   whereas split(/ /) will give you as many null
  3276.                   initial fields as there are leading spaces.
  3277.  
  3278.                   Example:
  3279.  
  3280.                       open(passwd, '/etc/passwd');
  3281.                       while (<passwd>) {
  3282.                           ($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split(/:/);
  3283.                           ...
  3284.                       }
  3285.  
  3286.                   (Note that $shell above will still have a newline on
  3287.                   it.  See the chop, chomp,  and join entries
  3288.                   elsewhere in this document.)
  3289.  
  3290.           sprintf FORMAT,LIST
  3291.                   Returns a string formatted by the usual printf
  3292.                   conventions of the C language.  (The * character for
  3293.                   an indirectly specified length is not supported, but
  3294.  
  3295.  
  3296.  
  3297.      Page 50                                         (printed 6/30/95)
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3305.  
  3306.  
  3307.  
  3308.                   you can get the same effect by interpolating a
  3309.                   variable into the pattern.)
  3310.  
  3311.           sqrt EXPR
  3312.                   Return the square root of EXPR.  If EXPR is omitted,
  3313.                   returns square root of $_.
  3314.  
  3315.           srand EXPR
  3316.                   Sets the random number seed for the rand operator.
  3317.                   If EXPR is omitted, does srand(time).  Of course,
  3318.                   you'd need something much more random than that for
  3319.                   cryptographic purposes, since it's easy to guess the
  3320.                   current time.  Checksumming the compressed output of
  3321.                   rapidly changing operating system status programs is
  3322.                   the usual method.  Examples are posted regularly to
  3323.                   comp.security.unix.
  3324.  
  3325.           stat FILEHANDLE
  3326.  
  3327.           stat EXPR
  3328.                   Returns a 13-element array giving the status info
  3329.                   for a file, either the file opened via FILEHANDLE,
  3330.                   or named by EXPR.  Returns a null list if the stat
  3331.                   fails.  Typically used as follows:
  3332.  
  3333.                       ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  3334.                          $atime,$mtime,$ctime,$blksize,$blocks)
  3335.                              = stat($filename);
  3336.  
  3337.                   If stat is passed the special filehandle consisting
  3338.                   of an underline, no stat is done, but the current
  3339.                   contents of the stat structure from the last stat or
  3340.                   filetest are returned.  Example:
  3341.  
  3342.                       if (-x $file && (($d) = stat(_)) && $d < 0) {
  3343.                           print "$file is executable NFS file\n";
  3344.                       }
  3345.  
  3346.                   (This only works on machines for which the device
  3347.                   number is negative under NFS.)
  3348.  
  3349.           study SCALAR
  3350.  
  3351.           study   Takes extra time to study SCALAR ($_ if unspecified)
  3352.                   in anticipation of doing many pattern matches on the
  3353.                   string before it is next modified.  This may or may
  3354.                   not save time, depending on the nature and number of
  3355.                   patterns you are searching on, and on the
  3356.                   distribution of character frequencies in the string
  3357.                   to be searched--you probably want to compare
  3358.                   runtimes with and without it to see which runs
  3359.                   faster.  Those loops which scan for many short
  3360.  
  3361.  
  3362.  
  3363.      Page 51                                         (printed 6/30/95)
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3371.  
  3372.  
  3373.  
  3374.                   constant strings (including the constant parts of
  3375.                   more complex patterns) will benefit most.  You may
  3376.                   have only one study active at a time--if you study a
  3377.                   different scalar the first is "unstudied".  (The way
  3378.                   study works is this: a linked list of every
  3379.                   character in the string to be searched is made, so
  3380.                   we know, for example, where all the 'k' characters
  3381.                   are.  From each search string, the rarest character
  3382.                   is selected, based on some static frequency tables
  3383.                   constructed from some C programs and English text.
  3384.                   Only those places that contain this "rarest"
  3385.                   character are examined.)
  3386.  
  3387.                   For example, here is a loop which inserts index
  3388.                   producing entries before any line containing a
  3389.                   certain pattern:
  3390.  
  3391.                       while (<>) {
  3392.                           study;
  3393.                           print ".IX foo\n" if /\bfoo\b/;
  3394.                           print ".IX bar\n" if /\bbar\b/;
  3395.                           print ".IX blurfl\n" if /\bblurfl\b/;
  3396.                           ...
  3397.                           print;
  3398.                       }
  3399.  
  3400.                   In searching for /\bfoo\b/, only those locations in
  3401.                   $_ that contain "f" will be looked at, because "f"
  3402.                   is rarer than "o".  In general, this is a big win
  3403.                   except in pathological cases.  The only question is
  3404.                   whether it saves you more time than it took to build
  3405.                   the linked list in the first place.
  3406.  
  3407.                   Note that if you have to look for strings that you
  3408.                   don't know till runtime, you can build an entire
  3409.                   loop as a string and eval that to avoid recompiling
  3410.                   all your patterns all the time.  Together with
  3411.                   undefining $/ to input entire files as one record,
  3412.                   this can be very fast, often faster than specialized
  3413.                   programs like _f_g_r_e_p(1).  The following scans a list
  3414.                   of files (@files) for a list of words (@words), and
  3415.                   prints out the names of those files that contain a
  3416.                   match:
  3417.  
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.      Page 52                                         (printed 6/30/95)
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3437.  
  3438.  
  3439.  
  3440.                       $search = 'while (<>) { study;';
  3441.                       foreach $word (@words) {
  3442.                           $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
  3443.                       }
  3444.                       $search .= "}";
  3445.                       @ARGV = @files;
  3446.                       undef $/;
  3447.                       eval $search;               # this screams
  3448.                       $/ = "\n";          # put back to normal input delim
  3449.                       foreach $file (sort keys(%seen)) {
  3450.                           print $file, "\n";
  3451.                       }
  3452.  
  3453.  
  3454.           substr EXPR,OFFSET,LEN
  3455.  
  3456.           substr EXPR,OFFSET
  3457.                   Extracts a substring out of EXPR and returns it.
  3458.                   First character is at offset 0, or whatever you've
  3459.                   set $[ to.  If OFFSET is negative, starts that far
  3460.                   from the end of the string.  If LEN is omitted,
  3461.                   returns everything to the end of the string.  You
  3462.                   can use the _s_u_b_s_t_r() function as an lvalue, in which
  3463.                   case EXPR must be an lvalue.  If you assign
  3464.                   something shorter than LEN, the string will shrink,
  3465.                   and if you assign something longer than LEN, the
  3466.                   string will grow to accommodate it.  To keep the
  3467.                   string the same length you may need to pad or chop
  3468.                   your value using _s_p_r_i_n_t_f().
  3469.  
  3470.           symlink OLDFILE,NEWFILE
  3471.                   Creates a new filename symbolically linked to the
  3472.                   old filename.  Returns 1 for success, 0 otherwise.
  3473.                   On systems that don't support symbolic links,
  3474.                   produces a fatal error at run time.  To check for
  3475.                   that, use eval:
  3476.  
  3477.                       $symlink_exists = (eval 'symlink("","");', $@ eq '');
  3478.  
  3479.  
  3480.           syscall LIST
  3481.                   Calls the system call specified as the first element
  3482.                   of the list, passing the remaining elements as
  3483.                   arguments to the system call.  If unimplemented,
  3484.                   produces a fatal error.  The arguments are
  3485.                   interpreted as follows: if a given argument is
  3486.                   numeric, the argument is passed as an int.  If not,
  3487.                   the pointer to the string value is passed.  You are
  3488.                   responsible to make sure a string is pre-extended
  3489.                   long enough to receive any result that might be
  3490.                   written into a string.  If your integer arguments
  3491.                   are not literals and have never been interpreted in
  3492.  
  3493.  
  3494.  
  3495.      Page 53                                         (printed 6/30/95)
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3503.  
  3504.  
  3505.  
  3506.                   a numeric context, you may need to add 0 to them to
  3507.                   force them to look like numbers.
  3508.  
  3509.                       require 'syscall.ph';               # may need to run h2ph
  3510.                       syscall(&SYS_write, fileno(STDOUT), "hi there\n", 9);
  3511.  
  3512.                   Note that Perl only supports passing of up to 14
  3513.                   arguments to your system call, which in practice
  3514.                   should usually suffice.
  3515.  
  3516.           sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
  3517.  
  3518.           sysread FILEHANDLE,SCALAR,LENGTH
  3519.                   Attempts to read LENGTH bytes of data into variable
  3520.                   SCALAR from the specified FILEHANDLE, using the
  3521.                   system call _r_e_a_d(2).  It bypasses stdio, so mixing
  3522.                   this with other kinds of reads may cause confusion.
  3523.                   Returns the number of bytes actually read, or undef
  3524.                   if there was an error.  SCALAR will be grown or
  3525.                   shrunk to the length actually read.  An OFFSET may
  3526.                   be specified to place the read data at some other
  3527.                   place than the beginning of the string.
  3528.  
  3529.           system LIST
  3530.                   Does exactly the same thing as "exec LIST" except
  3531.                   that a fork is done first, and the parent process
  3532.                   waits for the child process to complete.  Note that
  3533.                   argument processing varies depending on the number
  3534.                   of arguments.  The return value is the exit status
  3535.                   of the program as returned by the _w_a_i_t() call.  To
  3536.                   get the actual exit value divide by 256.  See also
  3537.                   the exec entry elsewhere in this document.
  3538.  
  3539.           syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
  3540.  
  3541.           syswrite FILEHANDLE,SCALAR,LENGTH
  3542.                   Attempts to write LENGTH bytes of data from variable
  3543.                   SCALAR to the specified FILEHANDLE, using the system
  3544.                   call _w_r_i_t_e(2).  It bypasses stdio, so mixing this
  3545.                   with prints may cause confusion.  Returns the number
  3546.                   of bytes actually written, or undef if there was an
  3547.                   error.  An OFFSET may be specified to place the read
  3548.                   data at some other place than the beginning of the
  3549.                   string.
  3550.  
  3551.           tell FILEHANDLE
  3552.  
  3553.           tell    Returns the current file position for FILEHANDLE.
  3554.                   FILEHANDLE may be an expression whose value gives
  3555.                   the name of the actual filehandle.  If FILEHANDLE is
  3556.                   omitted, assumes the file last read.
  3557.  
  3558.  
  3559.  
  3560.  
  3561.      Page 54                                         (printed 6/30/95)
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3569.  
  3570.  
  3571.  
  3572.           telldir DIRHANDLE
  3573.                   Returns the current position of the _r_e_a_d_d_i_r()
  3574.                   routines on DIRHANDLE.  Value may be given to
  3575.                   _s_e_e_k_d_i_r() to access a particular location in a
  3576.                   directory.  Has the same caveats about possible
  3577.                   directory compaction as the corresponding system
  3578.                   library routine.
  3579.  
  3580.           tie VARIABLE,PACKAGENAME,LIST
  3581.                   This function binds a variable to a package that
  3582.                   will provide the implementation for the variable.
  3583.                   VARIABLE is the name of the variable to be
  3584.                   enchanted.  PACKAGENAME is the name of a package
  3585.                   implementing objects of correct type.  Any
  3586.                   additional arguments are passed to the "new" method
  3587.                   of the package.  Typically these are arguments such
  3588.                   as might be passed to the _d_b_m__o_p_e_n() function of C.
  3589.  
  3590.                   Note that functions such as _k_e_y_s() and _v_a_l_u_e_s() may
  3591.                   return huge array values when used on large DBM
  3592.                   files.  You may prefer to use the _e_a_c_h() function to
  3593.                   iterate over large DBM files.  Example:
  3594.  
  3595.                       # print out history file offsets
  3596.                       tie(%HIST, NDBM_File, '/usr/lib/news/history', 1, 0);
  3597.                       while (($key,$val) = each %HIST) {
  3598.                           print $key, ' = ', unpack('L',$val), "\n";
  3599.                       }
  3600.                       untie(%HIST);
  3601.  
  3602.                   A package implementing an associative array should
  3603.                   have the following methods:
  3604.  
  3605.                       TIEHASH objectname, LIST
  3606.                       DESTROY this
  3607.                       FETCH this, key
  3608.                       STORE this, key, value
  3609.                       DELETE this, key
  3610.                       EXISTS this, key
  3611.                       FIRSTKEY this
  3612.                       NEXTKEY this, lastkey
  3613.  
  3614.                   A package implementing an ordinary array should have
  3615.                   the following methods:
  3616.  
  3617.                       TIEARRAY objectname, LIST
  3618.                       DESTROY this
  3619.                       FETCH this, key
  3620.                       STORE this, key, value
  3621.                       [others TBD]
  3622.  
  3623.                   A package implementing a scalar should have the
  3624.  
  3625.  
  3626.  
  3627.      Page 55                                         (printed 6/30/95)
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3635.  
  3636.  
  3637.  
  3638.                   following methods:
  3639.  
  3640.                       TIESCALAR objectname, LIST
  3641.                       DESTROY this
  3642.                       FETCH this,
  3643.                       STORE this, value
  3644.  
  3645.  
  3646.           time    Returns the number of non-leap seconds since
  3647.                   00:00:00 UTC, January 1, 1970.  Suitable for feeding
  3648.                   to _g_m_t_i_m_e() and _l_o_c_a_l_t_i_m_e().
  3649.  
  3650.           times   Returns a four-element array giving the user and
  3651.                   system times, in seconds, for this process and the
  3652.                   children of this process.
  3653.  
  3654.                       ($user,$system,$cuser,$csystem) = times;
  3655.  
  3656.  
  3657.           tr///   The translation operator.  See the _p_e_r_l_o_p manpage.
  3658.  
  3659.           truncate FILEHANDLE,LENGTH
  3660.  
  3661.           truncate EXPR,LENGTH
  3662.                   Truncates the file opened on FILEHANDLE, or named by
  3663.                   EXPR, to the specified length.  Produces a fatal
  3664.                   error if truncate isn't implemented on your system.
  3665.  
  3666.           uc EXPR Returns an uppercased version of EXPR.  This is the
  3667.                   internal function implementing the \U escape in
  3668.                   double-quoted strings.
  3669.  
  3670.           ucfirst EXPR
  3671.                   Returns the value of EXPR with the first character
  3672.                   uppercased.  This is the internal function
  3673.                   implementing the \u escape in double-quoted strings.
  3674.  
  3675.           umask EXPR
  3676.  
  3677.           umask   Sets the umask for the process and returns the old
  3678.                   one.  If EXPR is omitted, merely returns current
  3679.                   umask.
  3680.  
  3681.           undef EXPR
  3682.  
  3683.           undef   Undefines the value of EXPR, which must be an
  3684.                   lvalue.  Use only on a scalar value, an entire
  3685.                   array, or a subroutine name (using "&").  (Using
  3686.                   _u_n_d_e_f() will probably not do what you expect on most
  3687.                   predefined variables or DBM list values, so don't do
  3688.                   that.)  Always returns the undefined value.  You can
  3689.                   omit the EXPR, in which case nothing is undefined,
  3690.  
  3691.  
  3692.  
  3693.      Page 56                                         (printed 6/30/95)
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3701.  
  3702.  
  3703.  
  3704.                   but you still get an undefined value that you could,
  3705.                   for instance, return from a subroutine.  Examples:
  3706.  
  3707.                       undef $foo;
  3708.                       undef $bar{'blurfl'};
  3709.                       undef @ary;
  3710.                       undef %assoc;
  3711.                       undef &mysub;
  3712.                       return (wantarray ? () : undef) if $they_blew_it;
  3713.  
  3714.  
  3715.           unlink LIST
  3716.                   Deletes a list of files.  Returns the number of
  3717.                   files successfully deleted.
  3718.  
  3719.                       $cnt = unlink 'a', 'b', 'c';
  3720.                       unlink @goners;
  3721.                       unlink <*.bak>;
  3722.  
  3723.                   Note: unlink will not delete directories unless you
  3724.                   are superuser and the ----UUUU flag is supplied to Perl.
  3725.                   Even if these conditions are met, be warned that
  3726.                   unlinking a directory can inflict damage on your
  3727.                   filesystem.  Use rmdir instead.
  3728.  
  3729.           unpack TEMPLATE,EXPR
  3730.                   Unpack does the reverse of pack: it takes a string
  3731.                   representing a structure and expands it out into a
  3732.                   list value, returning the array value.  (In a scalar
  3733.                   context, it merely returns the first value
  3734.                   produced.)  The TEMPLATE has the same format as in
  3735.                   the pack function.  Here's a subroutine that does
  3736.                   substring:
  3737.  
  3738.                       sub substr {
  3739.                           local($what,$where,$howmuch) = @_;
  3740.                           unpack("x$where a$howmuch", $what);
  3741.                       }
  3742.  
  3743.                   and then there's
  3744.  
  3745.                       sub ordinal { unpack("c",$_[0]); } # same as ord()
  3746.  
  3747.                   In addition, you may prefix a field with a %<number>
  3748.                   to indicate that you want a <number>-bit checksum of
  3749.                   the items instead of the items themselves.  Default
  3750.                   is a 16-bit checksum.  For example, the following
  3751.                   computes the same number as the System V sum
  3752.                   program:
  3753.  
  3754.  
  3755.  
  3756.  
  3757.  
  3758.  
  3759.      Page 57                                         (printed 6/30/95)
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3767.  
  3768.  
  3769.  
  3770.                       while (<>) {
  3771.                           $checksum += unpack("%16C*", $_);
  3772.                       }
  3773.                       $checksum %= 65536;
  3774.  
  3775.                   The following efficiently counts the number of set
  3776.                   bits in a bit vector:
  3777.  
  3778.                       $setbits = unpack("%32b*", $selectmask);
  3779.  
  3780.  
  3781.           untie VARIABLE
  3782.                   Breaks the binding between a variable and a package.
  3783.                   (See _t_i_e().)
  3784.  
  3785.           unshift ARRAY,LIST
  3786.                   Does the opposite of a shift.  Or the opposite of a
  3787.                   push, depending on how you look at it.  Prepends
  3788.                   list to the front of the array, and returns the new
  3789.                   number of elements in the array.
  3790.  
  3791.                       unshift(ARGV, '-e') unless $ARGV[0] =~ /^-/;
  3792.  
  3793.                   Note the LIST is prepended whole, not one element at
  3794.                   a time, so the prepended elements stay in the same
  3795.                   order.  Use reverse to do the reverse.
  3796.  
  3797.           use Module LIST
  3798.  
  3799.           use Module
  3800.                   Imports some semantics into the current package from
  3801.                   the named module, generally by aliasing certain
  3802.                   subroutine or variable names into your package.  It
  3803.                   is exactly equivalent to
  3804.  
  3805.                       BEGIN { require Module; import Module LIST; }
  3806.  
  3807.                   If you don't want your namespace altered, use
  3808.                   require instead.
  3809.  
  3810.                   The BEGIN forces the require and import to happen at
  3811.                   compile time.  The require makes sure the module is
  3812.                   loaded into memory if it hasn't been yet.  The
  3813.                   import is not a builtin--it's just an ordinary
  3814.                   static method call into the "Module" package to tell
  3815.                   the module to import the list of features back into
  3816.                   the current package.  The module can implement its
  3817.                   import method any way it likes, though most modules
  3818.                   just choose to derive their import method via
  3819.                   inheritance from the Exporter class that is defined
  3820.                   in the Exporter module.
  3821.  
  3822.  
  3823.  
  3824.  
  3825.      Page 58                                         (printed 6/30/95)
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3833.  
  3834.  
  3835.  
  3836.                   Because this is a wide-open interface, pragmas
  3837.                   (compiler directives) are also implemented this way.
  3838.                   Currently implemented pragmas are:
  3839.  
  3840.                       use integer;
  3841.                       use sigtrap qw(SEGV BUS);
  3842.                       use strict  qw(subs vars refs);
  3843.                       use subs    qw(afunc blurfl);
  3844.  
  3845.                   These pseudomodules import semantics into the
  3846.                   current block scope, unlike ordinary modules, which
  3847.                   import symbols into the current package (which are
  3848.                   effective through the end of the file).
  3849.  
  3850.                   There's a corresponding "no" command that unimports
  3851.                   meanings imported by use.
  3852.  
  3853.                       no integer;
  3854.                       no strict 'refs';
  3855.  
  3856.                   See the _p_e_r_l_m_o_d manpage for a list of standard
  3857.                   modules and pragmas.
  3858.  
  3859.           utime LIST
  3860.                   Changes the access and modification times on each
  3861.                   file of a list of files.  The first two elements of
  3862.                   the list must be the NUMERICAL access and
  3863.                   modification times, in that order.  Returns the
  3864.                   number of files successfully changed.  The inode
  3865.                   modification time of each file is set to the current
  3866.                   time.  Example of a "touch" command:
  3867.  
  3868.                       #!/usr/bin/perl
  3869.                       $now = time;
  3870.                       utime $now, $now, @ARGV;
  3871.  
  3872.  
  3873.           values ASSOC_ARRAY
  3874.                   Returns a normal array consisting of all the values
  3875.                   of the named associative array.  (In a scalar
  3876.                   context, returns the number of values.)  The values
  3877.                   are returned in an apparently random order, but it
  3878.                   is the same order as either the _k_e_y_s() or _e_a_c_h()
  3879.                   function would produce on the same array.  See also
  3880.                   _k_e_y_s() and _e_a_c_h().
  3881.  
  3882.           vec EXPR,OFFSET,BITS
  3883.                   Treats a string as a vector of unsigned integers,
  3884.                   and returns the value of the bitfield specified.
  3885.                   May also be assigned to.  BITS must be a power of
  3886.                   two from 1 to 32.
  3887.  
  3888.  
  3889.  
  3890.  
  3891.      Page 59                                         (printed 6/30/95)
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3899.  
  3900.  
  3901.  
  3902.                   Vectors created with _v_e_c() can also be manipulated
  3903.                   with the logical operators |, & and ^, which will
  3904.                   assume a bit vector operation is desired when both
  3905.                   operands are strings.
  3906.  
  3907.                   To transform a bit vector into a string or array of
  3908.                   0's and 1's, use these:
  3909.  
  3910.                       $bits = unpack("b*", $vector);
  3911.                       @bits = split(//, unpack("b*", $vector));
  3912.  
  3913.                   If you know the exact length in bits, it can be used
  3914.                   in place of the *.
  3915.  
  3916.           wait    Waits for a child process to terminate and returns
  3917.                   the pid of the deceased process, or -1 if there are
  3918.                   no child processes.  The status is returned in $?.
  3919.  
  3920.           waitpid PID,FLAGS
  3921.                   Waits for a particular child process to terminate
  3922.                   and returns the pid of the deceased process, or -1
  3923.                   if there is no such child process.  The status is
  3924.                   returned in $?.  If you say
  3925.  
  3926.                       use POSIX "wait_h";
  3927.                       ...
  3928.                       waitpid(-1,&WNOHANG);
  3929.  
  3930.                   then you can do a non-blocking wait for any process.
  3931.                   Non-blocking wait is only available on machines
  3932.                   supporting either the _w_a_i_t_p_i_d(2) or _w_a_i_t_4(2) system
  3933.                   calls.  However, waiting for a particular pid with
  3934.                   FLAGS of 0 is implemented everywhere.  (Perl
  3935.                   emulates the system call by remembering the status
  3936.                   values of processes that have exited but have not
  3937.                   been harvested by the Perl script yet.)
  3938.  
  3939.           wantarray
  3940.                   Returns TRUE if the context of the currently
  3941.                   executing subroutine is looking for a list value.
  3942.                   Returns FALSE if the context is looking for a
  3943.                   scalar.
  3944.  
  3945.                       return wantarray ? () : undef;
  3946.  
  3947.  
  3948.           warn LIST
  3949.                   Produces a message on STDERR just like _d_i_e(), but
  3950.                   doesn't exit or throw an exception.
  3951.  
  3952.           write FILEHANDLE
  3953.  
  3954.  
  3955.  
  3956.  
  3957.      Page 60                                         (printed 6/30/95)
  3958.  
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.      PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111)))) UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV ((((RRRReeeelllleeeeaaaasssseeee 0000....0000 PPPPaaaattttcccchhhhlllleeeevvvveeeellll 00000000)))) PPPPEEEERRRRLLLLFFFFUUUUNNNNCCCC((((1111))))
  3965.  
  3966.  
  3967.  
  3968.           write EXPR
  3969.  
  3970.           write   Writes a formatted record (possibly multi-line) to
  3971.                   the specified file, using the format associated with
  3972.                   that file.  By default the format for a file is the
  3973.                   one having the same name is the filehandle, but the
  3974.                   format for the current output channel (see the
  3975.                   _s_e_l_e_c_t() function) may be set explicitly by
  3976.                   assigning the name of the format to the $~ variable.
  3977.  
  3978.                   Top of form processing is handled automatically:  if
  3979.                   there is insufficient room on the current page for
  3980.                   the formatted record, the page is advanced by
  3981.                   writing a form feed, a special top-of-page format is
  3982.                   used to format the new page header, and then the
  3983.                   record is written.  By default the top-of-page
  3984.                   format is the name of the filehandle with "_TOP"
  3985.                   appended, but it may be dynamically set to the
  3986.                   format of your choice by assigning the name to the
  3987.                   $^ variable while the filehandle is selected.  The
  3988.                   number of lines remaining on the current page is in
  3989.                   variable $-, which can be set to 0 to force a new
  3990.                   page.
  3991.  
  3992.                   If FILEHANDLE is unspecified, output goes to the
  3993.                   current default output channel, which starts out as
  3994.                   STDOUT but may be changed by the select operator.
  3995.                   If the FILEHANDLE is an EXPR, then the expression is
  3996.                   evaluated and the resulting string is used to look
  3997.                   up the name of the FILEHANDLE at run time.  For more
  3998.                   on formats, see the _p_e_r_l_f_o_r_m manpage.
  3999.  
  4000.                   Note that write is _N_O_T the opposite of read.
  4001.                   Unfortunately.
  4002.  
  4003.           y///    The translation operator.  See the section on _t_r///
  4004.                   in the _p_e_r_l_o_p manpage.
  4005.  
  4006.  
  4007.  
  4008.  
  4009.  
  4010.  
  4011.  
  4012.  
  4013.  
  4014.  
  4015.  
  4016.  
  4017.  
  4018.  
  4019.  
  4020.  
  4021.  
  4022.  
  4023.      Page 61                                         (printed 6/30/95)
  4024.  
  4025.  
  4026.  
  4027.